Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need help passing control array to a sub

Status
Not open for further replies.

DarkMercenary44

Technical User
May 19, 2000
55
US
I can't get this to work for some reason. I've gotten the actual code to work, but I got tired of having to have the same code in like 8 different locations in my project file. I want to create a sub that will do it. What it does is take in text that the user entered, and then displays it on the screen as if it was being typed out on a terminal, scrolling accross the screen. I'm using it for my encryption suite. Here's the variable that need passed.

label(index)-This is the begining of the array, index is 0. Only one on the form at this time.
frm-I think i need this in there so that the sub knows which form to put the new labels on.
text-text to display in window
starttop-Top position to start at
startleft-Left position to start at
maxtop-max top position the new controls can reach
maxleft-max left position the new controls can reach

I tried this:
Public Sub typetext(label as control, text as string, frm as form, maxtop as integer, maxleft as integer,optional starttop as integer,optional startleft as integer}

I even tried replacing label1 as control with
label1(integer) as control, but that didn't work either.

Public Sub typetext()
a = 1
c = 1
lenght = Len(Text1.Text) 'gets lenght of string
Do While a <= lenght
llet = Left(Text1.Text, a) 'gets all letters to pos a
rlet = Right(llet, 1) 'gets the last letter of llet
If rlet = &quot;|&quot; Then 'looks for | in rlet
oldtop = Label1(0).Top 'stores old top pos
Label1(0).Top = oldtop + 195 'sets new top pos
c = 1 'resets horz pos
rlet = &quot;>&quot; 'makes the | disappear
End If
lrlet = LCase(rlet)
Load Label1(a) 'loads new instance of label1
Debug.Print a
With Label1(a)
.BackColor = &HC000& 'sets cusor backcolor
.Top = Label1(0).Top 'sets cusor top
.Left = Label1(0).Left + (105 * c) 'sets cusor left
.Visible = True 'shows cursor
.Refresh 'force refresh
End With

b = 0
Do While b <= 10000 'acts as a timer so not to fast
b = b + 1
Loop
With Label1(a)
.BackColor = vbBlack 'undoes cursor colors
.Caption = lrlet 'sets caption of character
.Refresh 'forced refresh
End With
a = a + 1
c = c + 1
Loop
End Sub

theres the code I haven't change any of it to reflect the new variables yet, I have when I tried to use it, but i figured it would be better for you to see it in its workable state.

Thanks for any help you can give



DarkMercenary
darkmercenary44@earthlink.net

In the real world

As in dreams

Nothing is quite

What it seems

:Book of Counted Sorrows
 
I haven't try your code but instead of :
Public Sub typetext(label as control, text as string, frm as form, maxtop as integer, maxleft as integer,optional starttop as integer,optional startleft as integer)

I would type this :
Public Sub typetext(lbl as Label, sTxt as String, frm as form, maxtop as integer, maxleft as integer,optional starttop as integer,optional startleft as integer)

And for the rest of code, I will replace Label1 with lbl

It would be better to avoid using word such 'Label' for variable since VB used it as its object.

Hope this helps
;-)



 
I had this problem when passing controls in and out of DLLs. My solutions was to declare the variables as Object and then use TypeOf to check what was apssed to make sure it was the correct object. Not exactly wonderfull I know, but it worked!

James :) James Culshaw
jculshaw@active-data-solutions.co.uk
 
Thanks for the info, I havent' tested it yet, but I will soon, right now I'm building a listbox that lets you do colors for each list item.
DarkMercenary
darkmercenary44@earthlink.net

In the real world

As in dreams

Nothing is quite

What it seems

:Book of Counted Sorrows
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top