Solved

Function Call

Posted on 2000-05-03
5
181 Views
Last Modified: 2013-11-13
I have a string coming in via winsock.
Call it A$.

That string is of the format,
    "$int int stringVbCrLf"
Example:  "$1 1 String1||" The || representing the VbCrLf.

What I need to do is insert those three values as parameters of a function.
Does it work to do the following?
Call the function (subroutine) as

Sub1(A$)

and declare it as

Sub1(Int1, Int2, String1)

the other problem is that it is space delimited, not comma delimited.

Any help is appreciated
0
Comment
Question by:Crono15M
5 Comments
 
LVL 28

Expert Comment

by:AzraSound
ID: 2775285
do you have vb6? if so use the split function on the string, it will break it up into three elements of an array for you, then you can just pass that single array as a parameter
0
 
LVL 2

Expert Comment

by:Sage020999
ID: 2775286
You can not pass A$ in as an integer, this should give you a file type mismatch.  Can you change Sub1 to read a string and sub Call Sub1("A$",,)?

If you are using VB6 you can use the split command to parse your string.  This will allow you to pass an array if you like.

Hope this helps
0
 
LVL 14

Accepted Solution

by:
mcrider earned 100 total points
ID: 2775305
Coding Sub1 this way will allow you to access the variables inside the subroutine like you want:

    Sub Sub1(Source As String)
        Dim Int1 As Integer
        Dim Int2 As Integer
        Dim String1 As String
        Dim iVal As Long
        Dim jVal As Long
       
        iVal = InStr(1, Source, " ")
        jVal = InStr(iVal + 1, Source, " ")
        Int1 = CInt(Left$(Source, iVal))
        Int2 = CInt(Mid$(Source, iVal, jVal - iVal))
        String1 = Mid$(Source, jVal + 1)
        '****************************************************
        ' Int1 Int2 and String1 now contain the proper values
        ' The rest of your code goes here
        ' The debug lines below just show the variables...
        '****************************************************
        Debug.Print "Int1 is "; Int1
        Debug.Print "Int2 is "; Int2
        Debug.Print "String1 is "; String1
    End Sub





Then you just call it like this:  

      Sub1 A$



Cheers!®©
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 2775313
after creating the array just pass it to the function, for example


Private Sub Command1_Click()
  Dim arr As Variant
  arr = Split(A$)
  Call MyFunc(arr)
End Sub

Function Sub1 MyFunc(arr As Variant)
  Dim i As Integer
  For i = 0 To UBound(arr)
    Debug.Print arr(i)
  Next
End Function

that should print each element of your array
0
 
LVL 32

Expert Comment

by:bhess1
ID: 2775339
Let's assume your string can have embedded spaces.  This means that the Split function won't work.  So, let's parse it.


Sub ParseString(S as String, I1 as Integer, I2 as Integer)

Dim I as Integer, J as Integer
I=InStr(S," ")
If I = 0 Then
   ' handle bad data here
   Exit Sub
Else
   I1 = Val(Left(S,I))
End If

I = I + 1
J = InStr(I, S, " ")
If J = 0 Then
   ' handle bad data here
   Exit Sub
Else
   I2 = Val(Mid(S,I,J))
End If

S = Mid(S,J+1) ' take remainder of string
If Right(S,2) = vbCrLf Then
   If Len(S)>2 Then
      S = Left(S,Len(S)-2)
   Else
      S = ""
   End If
Else
   ' handle bad data here
   Exit Sub
End If

End Sub

To use this, you would pass the string variable in the first parameter, and two integer variables as the second and third parameters:

Dim I1 as Integer, I2 as Integer, A as String

ParseString A, I1, I2

Then you can call your subroutine:

Sub1 A, I1, I2


Of course, you can always embed this code in your 'Sub1' and parse it there.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
WPF issue with Trigger 2 105
vb6 - Transfer from MSHFlexgrid1 to xls issue 8 51
Problem to App 4 78
Python 3.5.2 32 virtualenv problems 3 34
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

816 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now