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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problems passing arguements

Status
Not open for further replies.

Catrina

Programmer
Feb 11, 2000
70
US
I'm new to programming, and trying to master passing arguments. I can't figure this problem out. I get the error &quot;Compile Error Expected: =&quot; when I try to call a sub. Here is the sub (Not finished yet):<br><br>Private Sub CheckOutPut(K%, ZOUT$)<br>&nbsp;&nbsp;&nbsp;If K% = 1 Then GoTo 16001<br>&nbsp;&nbsp;&nbsp;If K% = 2 Then GoTo 16002<br>&nbsp;&nbsp;&nbsp;If K% = 3 Then GoTo 16003<br>&nbsp;&nbsp;&nbsp;If K% = 4 Then GoTo 16004<br>&nbsp;&nbsp;&nbsp;If K% = 5 Then GoTo 16005<br>16001<br>&nbsp;&nbsp;&nbsp;If Val(ZOUT$) &gt; 0 Then Ck1$ = &quot;Y&quot;<br>&nbsp;&nbsp;&nbsp;If Mid(CT1$, 1, 2) &gt;= &quot;32&quot; And Mid(CT1$, 1, 2)&lt;= &quot;41&quot;Then<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Ck1$ = &quot;Y&quot;<br>&nbsp;&nbsp;&nbsp;End If<br>&nbsp;&nbsp;&nbsp;Exit Sub<br>16002<br>16003<br>16004<br>16005<br>End Sub<br><br>Here is how I am calling it:<br><br>Private Sub txtGross_KeyPress(KeyAscii As Integer)<br>KeyAscii = Asc(UCase(Chr(KeyAscii)))<br>ZOUT$ = Chr(KeyAscii)<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;If KeyAscii = 13 Then<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;KeyAscii = 0<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Vis% = 2<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ZOUT$ = txtGross.Text<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CheckOutPut(1, ZOUT$)''''Here is the line I get the<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;''''Error on <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Mid(CT1$, 15, 8) = ZOUT$<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Color<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;End If<br>End Sub<br><br><br>It will let me pass one or the other, but not both. I've tried setting K%=1 then passing K%, but still wouldn't work. Thanks for any help.<br><br>Catrina
 
You must put &quot;:&quot; after the label<br><br>example:<br><br><br>sub example()<br>on error go to lblerror<br><br>'some code<br><br>lblerror:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'things to do in the label<br>end sub<br><br><br><br><br>
 
I think you misunderstand, I am not trapping an error, I am getting a compile error. The '''Here is the line I get the error on'' is remarked out, just put it there to show the line the error occurs on. <br><br>Catrina
 
Catrina<br><br>There are two ways to call a sub/function:<br>1st is to use the word 'Call' and then your sub/function followed by any paramaters enclosed in brackets.<br>2nd is to omit the word 'Call' only using the name of your sub/function followed by your parameters.&nbsp;&nbsp;In this case though, you don't include the brackets.<br><br>I think that your statement should be either CheckOutPut 1, ZOUT$ or CALL Checkoutput(1,Zout$)<br><br>Don't know about the rest of the code as some of the variables are not defined etc. but I think the above should work.
 
Thanks, using Call worked!<br><br>Catrina
 
DSJ1967 is correct. A sub call does not include parenthesis.&nbsp;&nbsp;The compiler sees the parenthisis and assumes a function.&nbsp;&nbsp;Functions are rValues and thus require an lValue and equal sign to make the exchange.&nbsp;&nbsp;The CALL verb alerts the compiler to the upcoming nonstandard syntax.&nbsp;&nbsp;There are cases where it is necessary to do the CALL.&nbsp;&nbsp;I don't remember what they are.<br><br>Recent trends in Visual basic have eliminated the need for line numbers.&nbsp;&nbsp;A select case statement makes the code look much nicer.&nbsp;&nbsp;<br><br>
 
Will makes a good point<br><br>Try this code Catrina<br><FONT FACE=monospace><b><br>Select Case K%<br>&nbsp;&nbsp;&nbsp;&nbsp;Case 1<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' code to deal with K=1<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;If Val(ZOUT$) &gt; 0 Then Ck1$ = &quot;Y&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;If Mid(CT1$, 1, 2) &gt;= &quot;32&quot; And Mid(CT1$, 1, 2)&lt;= &quot;41&quot;Then<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Ck1$ = &quot;Y&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;End If<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Exit Sub<br>&nbsp;&nbsp;&nbsp;&nbsp;Case 2<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' code to deal with K=2<br>&nbsp;&nbsp;&nbsp;&nbsp;Case 3<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' code to deal with K=3<br>&nbsp;&nbsp;&nbsp;&nbsp;Case 4<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' code to deal with K=4<br>&nbsp;&nbsp;&nbsp;&nbsp;Case 5<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' code to deal with K=5<br>End Select<br></font></b><br> <p>Mike<br><a href=mailto:michael.j.lacey@ntlworld.com>michael.j.lacey@ntlworld.com</a><br><a href= Cargill's Corporate Web Site</a><br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top