How to return multiple value from a function in VB 6.0
Any suggestion sir/madam?
How about arrays?
Private Function ReturnArrays(SomeArgs As String) As String() 'Code goes here End Function
You can also use user define types and even classes.
Thanks for replying, Yes, it can be done using array. I have tried like this
Private Sub Command1_Click() Text2.Text = ReturnPrevCurNxt(Val(Text1.Text))(0) Text3.Text = ReturnPrevCurNxt(Val(Text1.Text))(1) Text4.Text = ReturnPrevCurNxt(Val(Text1.Text))(2) End Sub
Function ReturnPrevCurNxt(x As Integer) Dim arr(0 To 2) As Double arr(0) = x - 1 arr(1) = x arr(2) = x + 1 ReturnPrevCurNxt = arr End Function
But, I have not tried using user define type or classes yet.
This an example about struct of employee combining with array
Public Type Employee EmpNo As Integer EmpName As String EmpPhone As String End Type Public Sub SetEmployee(ByRef emp() As Employee, ByVal i As Integer) ReDim emp(i) End Sub Public Sub SetEmpData(ByRef emp() As Employee, ByVal i As Integer, ByVal no As Integer, ByVal name As String, ByVal phone As String) emp(i).EmpNo = no emp(i).EmpName = name emp(i).EmpPhone = phone End Sub 'GetEmpData will return array containing employee details Public Function GetEmpData(ByRef emp() As Employee, ByVal i As Integer) As Employee GetEmpData = emp(i) End Function
All inputs will use inputbox and just add two button for set and get employee details
Dim NewEmp() As Employee ' declare array as struct of employee Dim i As Integer Private Sub Command1_Click() ' how many employee to add temp = InputBox("How many employee ?") SetEmployee NewEmp, Int(temp - 1) ' add employee detail For i = 0 To UBound(NewEmp) EmpNos = InputBox("Emp " & i + 1 & " No") EmpNames = InputBox("Emp " & i + 1 & " Name") EmpPhones = InputBox("Emp " & i + 1 & " phone") SetEmpData NewEmp, i, EmpNos, EmpNames, EmpPhones Next End Sub Private Sub Command2_Click() ' Extract detail of employee for each array For i = 0 To UBound(NewEmp) MsgBox GetEmpData(NewEmp, i).EmpNo & "," & GetEmpData(NewEmp, i).EmpName & "," & GetEmpData(NewEmp, i).EmpPhone Next End Sub
Edited 3 Years Ago by Jx_Man
JX_man, thanks for your example sir.
I have done with my previous example. Its working nicely.
Type UDT a As Integer b As Integer c As Integer End Type Public Function ReturnPrevCurNxt(x As Integer) As UDT ReturnPrevCurNxt.a = x - 1 ReturnPrevCurNxt.b = x ReturnPrevCurNxt.c = x + 1 End Function
Private Sub Command1_Click() Text2.Text = ReturnPrevCurNxt(Val(Text1.Text)).a Text3.Text = ReturnPrevCurNxt(Val(Text1.Text)).b Text4.Text = ReturnPrevCurNxt(Val(Text1.Text)).c End Sub
So, I am going to closed this thread as it has solved.
Thank you all
Hey, so I wanna ask how I need to create a method who will remove word if in that word is 2 same chars. Example: "Potato" in this word there is a 2 "o" chars so this word will need to be removed. "Forum" in this word there is no ...
Hi I'm having a problem implementing a mini shopping cart drop down in the header to show the user all the products they have in their shopping cart. It seems the only solution for this is Ajax, and I've looked all over and can't find anything that I could possibly ...
Hi. Im using vb 2010. I want to dynamically add textboxes to my form by clicking on a button. I've google searched and so far this code worked:
Private Sub btn_addline_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_addline.Click Dim txtB1 As New TextBox Dim i For i = ...