Hey guys, I've worked far long enough so this is kind of a last resort kinda post. I'm having trouble with functions and arrays, I need to write a function that returns an array of userinput (text from textbox, split by characters/spaces). I can't seem to work out returning the array to use on my other functions, anybody have an idea what I'm doing wrong? Maybe what I should be doing instead? I am a novice in VB.Net- sometimes it clicks sometimes it doesn't, please let me know what you guys think. Thanks.
This is the incomplete code I currently have in my function, for grabbing userinput to begin with...
Below is my original sum formula for finding numbers between comma's, without using an Array.
This is the incomplete code I currently have in my function, for grabbing userinput to begin with...
Public Function Example(ByVal test As String) As String()
Dim str As String
Dim strArr() As String
Dim count As Integer
Dim output As String
str = Form1.Textbox1.Text
strArr = str.Split(CChar(CChar(",") & (" ")))
For count = 0 To strArr.GetUpperBound(0)
MessageBox.Show(strArr(count))
Next
Return ?
End Function
Below is my original sum formula for finding numbers between comma's, without using an Array.
Public Function SumFunction(ByVal srchTerm As String, ByVal stringToSearch As String) As Integer
Dim intGetPosition As Integer = stringToSearch.IndexOf(srchTerm)
Dim comma As Integer = 0
Dim comma2 As Integer = 0
Dim count As Integer = 0
Dim total As Integer = 0
Dim number As String
Do While comma > -1
Try
comma = stringToSearch.IndexOf(srchTerm, comma2)
'If/When there's no comma at the end...
If comma = -1 Then
comma = stringToSearch.IndexOf(srchTerm, comma2)
number = stringToSearch.Substring(comma2)
total = CInt(total + CDbl(number))
comma2 = comma + 1
count = count + 1
End If
'When there's still a comma at the end to look for...
number = stringToSearch.Substring(comma2, comma - comma2)
total = CInt(total + CDbl(number))
comma2 = comma + 1
count = count + 1
Catch ex As Exception
'Catch and do nothing
End Try
Loop
'Return total sum
Return total
End Function
Public Sub SumSub()
'calling function "SumFunction" FOR a comma string, INSIDE of textbox1.text
Dim Sum As Integer = SumFunction(",", t1.Text)
'OUTPUT SUM FUNCTION TO TEXTBOX
t1.Text = CStr(Sum)
End Sub
Public Sub btnTotal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTotal.Click
Call SumSub()
End Sub