why does this crash the program? (vb)

Associate
Joined
1 Mar 2006
Posts
425
hi
form consists of a richtextbox. and textbox and a button

contents of smile.text is "example1"

Code:
Public Sub Form_Load()
On Error Resume Next
ReDim Emo(1)
ReDim Icon(1)

Emo(1) = ":)"
Icon(1) = smile.text

end sub

private sub button_click()
 txtmain.SelRTF = Icon(i)
end sub

so when you type :) into the textbox and press the button

the richtextbox should show the text example1


but the program just hangs


any help would be great
 
ok the contents of the smile.text box is

{\rtf1\ansi
\ansicpg1
252\deff0
\deflang1
033{\fontt
bl{\f0\fnil\
fcharset0
MS Sans
Serif;}}
\uc1\pard
\f0\fs17{\
pict\wmet
afile8\pic
w502\pich
502\picwg
oal285\pic
hgoal285
01000900
00037202
00000000
5c020000
00000500
00000b02
00000000
05000000
0c02f601f
6015c
02000043
0f2000cc0
00000130
01300000
00000f601
f60100000
00028000
00013000
00013000
000
01001800
00000000
74040000
c40e0000
c40e0000
00000000
00000000f
fffffffffffffffff
ffff
ffffffffd4d5
d6a9b3b8
869fab5f8
da248829
a5c899c8
199a4a5a
eb3d0d1d
1fffffffffffffff
f
ffffffffffffff0
00000fffffff
fffffffffffe5e
5e5a6b3b
85b98b12
99fcf27a6
d726afe32
4b2
e926abe0
27a0d028
90bb5587
9e9faaafe
0e1e1fffffff
fffffffffff000
000fffffffffff
fd9d9
da90a8b3
28a5d429
b5e629bc
ee28baed
26b8ec25
b6eb25b4
ea23b4ea
22b3e926
a6d8278a
b48499
a3d3d4d4f
fffffffffff000
000ffffffe5
e5e590a9
b52cafde3
0c3f130c4
f22ea3dc2
ea4dc269
9
d82698d7
2598d725
98d72598
d722b3e9
23b4ea29
91bb859a
a4e0e1e1f
fffff000000
ffffffa9b6
bb2db3e1
35ccf436c
ff633ade1
3099d61f3
f9f203fa02
03f9f1f3f9f
1f3f9f2689
ce2699d7
23b3
ea23b3ea
288cb59fa
aafffffff000
000d7d8d
862a4bd3
9ccf43dd8
f93ed9fa3
49fd91f3f9
f35a0
d939b5e6
39b5e639
b5e63098
d51f3e9f2
789cd26b
7ec22b3e
926a6d85
7899ecfd0
d0000000
b1bb
bf32c0ec4
1dcfc42de
fe40ddfd2
03f9f36a1
da39b6e7
40dcfc3fd
9f93bd5f9
33ace130
99d51f3f
9f24b6ea2
5b6eb22b
3e92890b
aa5aeb30
000008fac
b939cff44
3e1ff46e3f
f47e3ff47e
4ff47e3
ff45e2ff44
e0ff42defe
3fdbfb3ed
7f837d1f7
33c8f52dc
1f128baee
25b4ea27
a0cf8098a
40000
0067a7bf4
1dbfb48e3
ff4ae6fe4b
e6fd4ce7f
c4ae6fc49
e5fd48e4ff
46e3ff43df
ff41dbfb3d
d8
f838cff632
c7f42bbef
027b8ed2
7ace15d8
a9d00000
04da6c74
9e4fe4be7
fb4de8fb3f
c0de2778
99287899
3fc0df4be
6fc49e4fd
45e2ff39b
9db27789
92878993
1aed62fc3
f229bbed2
4b4ea478
2
9a000000
69a9c147
e3ff4feafc
50ecfe277
8990d1f53
0d1f53287
8994feafc
4de7fb49e
4fd2778
990d1e52
0d1e5227
789932c7f
42abdee2
6b0e45f8e
a2000000
92afbb42d
af951edfd
53edfe277
7
991b2b58
1c2c5d44
7c9352ecf
d4eeafc4b
e7fc27789
91b2a571
c2c5d447
d9434caf6
2dc0f029a
a
da859fab0
00000b2b
cbf3acef4
53edfe54f
0fd447c94
ffffffffffff44
7c9453edf
d51ebfd4f
e9
fc447d94ff
ffffffffff457
d9435cdf5
2ec2f128a
2d0a9b3b
8000000d
9dada68a
dc34ae4fd
56ef
fc447c94ff
ffffffffff447
d9454edfc
52ecfd4ee
afc447d94
ffffffffffff44
7d9436cff
62fbb
eb5c9ab2
d4d5d600
0000ffffffa
cb9be39c
df357f0fd6
9adba447
d94447d9
468adba5
5f0fd52ec
fd4eeafc6
1a9bb447
d94457d9
45aa5bb3
8cff62ca8
d6a6b3b8f
fffff000000
ffffffe7e7e
796b0
ba3ed3f55
7f3fe57f4f
e56f2fd56f
1fd53effd5
1edfd4ee9
fc4ae6fc4
7e3ff42def
e3dd9f92f
b5
e18fa7b3e
5e5e5ffffff
000000fffff
fffffffdadbd
b96b0ba3
acff34ce7f
c57f0fd54f
0fd53ee
fd4feafc4d
e9fc4be6f
d46e3ff3d
d2f631b8e
390a9b5d
9d9dafffffff
fffff000000
ffffffffff
ffffffffe7e7
e7adb9be
68adc33b
cff345ddfb
4be5fd4ee
8fb45e2ff3
cd3f634c4
ef62a5bea
9b6
bbe5e5e5f
fffffffffffffffff
000000fffff
fffffffffffffffff
ffffffffd9da
dab2bcbf9
2af
bb69a9c1
4da6c669
a7bf90adb
9b1bbbfd7
d8d8fffffffff
fffffffffffffffff
ffff000000
0300
00000000
}}

which is Richtext code for a smiley face icon

so when you try :) in the textbox and press the command button it show the image in the Richtextbox
 
hi

yeah emo and icon are declared

why do i need to declare smile and txtmain?

smile is just a normal textbox with the RichTextFormat Code , and Txtmain is a Richtextbox
 
emo and icon are

Code:
dim emo as string 
dim icon as string

in a public sub on another form (i think)

when i stepped into the code and hovered the :) part of the code



"it stated subscript out of range"

and smile.text = "object variable or with block variable not set"

heres the original code taken from a OCX project, what i did was try and turn it into a .exe

emoticons work fine in the ocx

http://pastebin.com/R7KiBxUR

you will need to look at

Code:
Private Sub UserControl_Initialize()

which i put in form_initialize on my project

thanks
 
hi

thanks for that

so do you think i need to

dim emo as string
dim icon as string

in the

Public Sub Form_Load()
On Error Resume Next
ReDim Emo(1)
ReDim Icon(1)

Emo(1) = ":)"
Icon(1) = smile.text

end sub

i thought that becuase both SUBS were Public they could talk to each other
 
Well first off get rid of VB6 and start using something more recent.

Both Icon and Emo are strings not arrays. You cannot redim something that isnt an array.


Code:
Dim Emo as string         'These are only available in the form they are declared
Dim Icon as string        

Public Sub Form_Load()
On Error Resume Next       'remove this its hiding errors, only use error handling if you have a specific need for it

Emo = ""     'dont know why you would want to do this on a form load but it will blank the contents of the string
Icon = "" 

Emo = ":D"
Icon = smile.text

end sub

hi

i didnt do

Code:
Emo = ""     'dont know why you would want to do this on a form load but it will blank the contents of the string
Icon = ""

and they are arrays because

Code:
Public Sub Form_Load()
ReDim Emo(2)
ReDim Icon(2)

Emo(1) = ":)"
Icon(1) = smile.text

Emo(1) = ":("
Icon(1) = cry.text


end sub

there is 16 parts to the array in the original code, i only showed one becuase i thought it would make it clearer

thanks
 
Code:
Option Explicit

Dim CMode          As String
Dim sData          As String
Dim sChannel       As String
Dim HostGroup      As String
Dim OwnerGroup     As String
Dim GuideGroup     As String
Dim sRoomList      As String
Dim lFoundPosition As Long
Dim Color          As Boolean
Dim sList          As ListItem
Dim i              As Integer


Private Sub Form_Load()

ReDim Emo(16)
    ReDim Icon(16)

    Emo(1) = "(H) (h)"
    Icon(1) = frmEmo.sunglass.Text
    Emo(2) = ":P :p :-P :-p"
    Icon(2) = frmEmo.Tongue.Text
    Emo(3) = ":O :o :-o :-O"
    Icon(3) = frmEmo.Oh.Text
    Emo(4) = "(Y) (y)"
    Icon(4) = frmEmo.thumbsup.Text
    Emo(5) = ":) :-)"
    Icon(5) = frmEmo.Smile.Text
    Emo(6) = ":D :-D :d :-d :>"
    Icon(6) = frmEmo.BSmile.Text
    Emo(7) = ":( :-("
    Icon(7) = frmEmo.Sad.Text
    Emo(8) = ":| :-|"
    Icon(8) = frmEmo.shut.Text
    Emo(9) = ":'("
    Icon(9) = frmEmo.cry.Text
    Emo(10) = "(F) (f)"
    Icon(10) = frmEmo.flower.Text
    Emo(11) = ":s :S :-S :-s"
    Icon(11) = frmEmo.SS.Text
    Emo(12) = ";) ;-)"
    Icon(12) = frmEmo.knipoog.Text
    Emo(13) = ":@"
    Icon(13) = frmEmo.angry.Text
    Emo(14) = "(K) (k)"
    Icon(14) = frmEmo.kiss.Text
    Emo(15) = ":$ :-$"
    Icon(15) = frmEmo.blush.Text
    Emo(16) = "(A) (a)"
    Icon(16) = frmEmo.angel.Text
end sub

Private Sub SetEmo()
Dim j As Integer
Dim CharCombo() As String
Dim lFoundPosition2 As Long

On Error Resume Next
For i = 0 To 30
    CharCombo = Split(Emo(i), " ")
    For j = 0 To UBound(CharCombo)
        lFoundPosition2 = InStr(lFoundPosition, txtMain.Text, CharCombo(j))
        While lFoundPosition2 > 0
            txtMain.SelStart = lFoundPosition2 - 1
            txtMain.SelLength = Len(CharCombo(j))
            txtMain.SelRTF = Icon(i)
            lFoundPosition2 = InStr(lFoundPosition2, txtMain.Text, CharCombo(j))
        Wend
    Next j
Next i

lFoundPosition = Len(txtMain.Text) - 1

End Sub
 
hi

when i run it and try to pass ":@" without quotes through it

i get this error

erroroh.png
 
sorry i forgot to mention i fixed this :(


i just put all the redim()s into the Setemo Sub

and it work perfect

thanks for all your help
 
Back
Top Bottom