ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Splitting variables with a comma error with slashes (https://www.excelbanter.com/excel-programming/402202-splitting-variables-comma-error-slashes.html)

[email protected]

Splitting variables with a comma error with slashes
 
here is the code i was using to split the variable, however
the information is put together like this :

FirstName,Lastname,Mother:1,Mychild,10/12/2007 ,10/11/2007


now the problem im having is when it gets to the date, it doesnt
return the date so TxtServed and TxtIssued are still blank

vntX = Split(strToSplit, ",")

If intChoose = 0 Then
SplitMe = vntX(0) & "," & vntX(1) ' First Name Last Name
ElseIf intChoose = 2 Then
SplitMe = vntX(2) ' MoFa CBo Box
ElseIf intChoose = 1 Then
TxtFirstName = vntX(0) ' First Name
TxtLastName = vntX(1) ' Last Name
CBOMoFa = vntX(2) ' parent type
TxtChild = vntX(3) ' Childs Name
If UBound(vntX) = 4 Then
TxtIssued = vntX(4) ' issued
Else
TxtIssued = ""
End If
If UBound(vntX) = 5 Then
TxtServed = vntX(5) ' served
Else
TxtServed = ""
End If
End If

Bob Phillips

Splitting variables with a comma error with slashes
 
If intChoose is 1 TxtServed loads okay for me, TxtIssued is empty.

Why do you only select the one?

Maybe it should be

vntX = Split(strToSplit, ",")

If intChoose = 0 Then
SplitMe = vntX(0) & "," & vntX(1) ' First Name Last Name
ElseIf intChoose = 2 Then
SplitMe = vntX(2) ' MoFa CBo Box
ElseIf intChoose = 1 Then
TxtFirstName = vntX(0) ' First Name
TxtLastName = vntX(1) ' Last Name
CBOMoFa = vntX(2) ' parent type
TxtChild = vntX(3) ' Childs Name
If UBound(vntX) 3 Then
TxtIssued = vntX(4) ' issued
Else
TxtIssued = ""
End If
If UBound(vntX) 4 Then
TxtServed = vntX(5) ' served
Else
TxtServed = ""
End If
End If


--
---
HTH

Bob


(there's no email, no snail mail, but somewhere should be gmail in my addy)



wrote in message
...
here is the code i was using to split the variable, however
the information is put together like this :

FirstName,Lastname,Mother:1,Mychild,10/12/2007 ,10/11/2007


now the problem im having is when it gets to the date, it doesnt
return the date so TxtServed and TxtIssued are still blank

vntX = Split(strToSplit, ",")

If intChoose = 0 Then
SplitMe = vntX(0) & "," & vntX(1) ' First Name Last Name
ElseIf intChoose = 2 Then
SplitMe = vntX(2) ' MoFa CBo Box
ElseIf intChoose = 1 Then
TxtFirstName = vntX(0) ' First Name
TxtLastName = vntX(1) ' Last Name
CBOMoFa = vntX(2) ' parent type
TxtChild = vntX(3) ' Childs Name
If UBound(vntX) = 4 Then
TxtIssued = vntX(4) ' issued
Else
TxtIssued = ""
End If
If UBound(vntX) = 5 Then
TxtServed = vntX(5) ' served
Else
TxtServed = ""
End If
End If




joel

Splitting variables with a comma error with slashes
 

Try this code

Sub getfields()

Data = Range("A1")

firstname = Trim(Left(Data, (InStr(Data, ",") - 1)))
Data = Mid(Data, (InStr(Data, ",") + 1))
lastname = Trim(Left(Data, (InStr(Data, ",") - 1)))
Data = Mid(Data, (InStr(Data, ",") + 1))
mother = Trim(Left(Data, (InStr(Data, ",") - 1)))
mothernumber = Val(Trim(Mid(Data, (InStr(Data, ":") + 1))))
Data = Mid(Data, (InStr(Data, ",") + 1))
mychild = Trim(Left(Data, (InStr(Data, ",") - 1)))
Data = Mid(Data, (InStr(Data, ",") + 1))
firstdate = DateValue(Trim(Left(Data, (InStr(Data, ",") - 1))))
seconddate = DateValue(Trim(Mid(Data, (InStr(Data, ",") + 1))))

End Sub

" wrote:

here is the code i was using to split the variable, however
the information is put together like this :

FirstName,Lastname,Mother:1,Mychild,10/12/2007 ,10/11/2007


now the problem im having is when it gets to the date, it doesnt
return the date so TxtServed and TxtIssued are still blank

vntX = Split(strToSplit, ",")

If intChoose = 0 Then
SplitMe = vntX(0) & "," & vntX(1) ' First Name Last Name
ElseIf intChoose = 2 Then
SplitMe = vntX(2) ' MoFa CBo Box
ElseIf intChoose = 1 Then
TxtFirstName = vntX(0) ' First Name
TxtLastName = vntX(1) ' Last Name
CBOMoFa = vntX(2) ' parent type
TxtChild = vntX(3) ' Childs Name
If UBound(vntX) = 4 Then
TxtIssued = vntX(4) ' issued
Else
TxtIssued = ""
End If
If UBound(vntX) = 5 Then
TxtServed = vntX(5) ' served
Else
TxtServed = ""
End If
End If


[email protected]

Splitting variables with a comma error with slashes
 
On Dec 4, 12:45 pm, Joel wrote:
Try this code

Sub getfields()

Data = Range("A1")

firstname = Trim(Left(Data, (InStr(Data, ",") - 1)))
Data = Mid(Data, (InStr(Data, ",") + 1))
lastname = Trim(Left(Data, (InStr(Data, ",") - 1)))
Data = Mid(Data, (InStr(Data, ",") + 1))
mother = Trim(Left(Data, (InStr(Data, ",") - 1)))
mothernumber = Val(Trim(Mid(Data, (InStr(Data, ":") + 1))))
Data = Mid(Data, (InStr(Data, ",") + 1))
mychild = Trim(Left(Data, (InStr(Data, ",") - 1)))
Data = Mid(Data, (InStr(Data, ",") + 1))
firstdate = DateValue(Trim(Left(Data, (InStr(Data, ",") - 1))))
seconddate = DateValue(Trim(Mid(Data, (InStr(Data, ",") + 1))))

End Sub



" wrote:
here is the code i was using to split the variable, however
the information is put together like this :


FirstName,Lastname,Mother:1,Mychild,10/12/2007 ,10/11/2007


now the problem im having is when it gets to the date, it doesnt
return the date so TxtServed and TxtIssued are still blank


vntX = Split(strToSplit, ",")


If intChoose = 0 Then
SplitMe = vntX(0) & "," & vntX(1) ' First Name Last Name
ElseIf intChoose = 2 Then
SplitMe = vntX(2) ' MoFa CBo Box
ElseIf intChoose = 1 Then
TxtFirstName = vntX(0) ' First Name
TxtLastName = vntX(1) ' Last Name
CBOMoFa = vntX(2) ' parent type
TxtChild = vntX(3) ' Childs Name
If UBound(vntX) = 4 Then
TxtIssued = vntX(4) ' issued
Else
TxtIssued = ""
End If
If UBound(vntX) = 5 Then
TxtServed = vntX(5) ' served
Else
TxtServed = ""
End If
End If- Hide quoted text -


- Show quoted text -


the problem with this is that
either 1 or both of these might be empty, and im not that familiar
with using ubound i actually had someone help me with this a while
back on here.. so if possible could it be explained, or help me to
figure it out im currently looking through forums online to find out
exactly how to use it :|
TxtIssued = DateValue(Trim(Left(data, (InStr(data, ",") - 1))))
TxtServed = DateValue(Trim(Mid(data, (InStr(data, ",") + 1))))

joel

Splitting variables with a comma error with slashes
 
I added a check using ISDATE() to prevent errors from occuring.

Sub getfields()

Data = Range("A1")

firstname = Trim(Left(Data, (InStr(Data, ",") - 1)))
Data = Mid(Data, (InStr(Data, ",") + 1))
lastname = Trim(Left(Data, (InStr(Data, ",") - 1)))
Data = Mid(Data, (InStr(Data, ",") + 1))
mother = Trim(Left(Data, (InStr(Data, ",") - 1)))
mothernumber = Val(Trim(Mid(Data, (InStr(Data, ":") + 1))))
Data = Mid(Data, (InStr(Data, ",") + 1))
mychild = Trim(Left(Data, (InStr(Data, ",") - 1)))
Data = Mid(Data, (InStr(Data, ",") + 1))
firstdate = Trim(Left(Data, (InStr(Data, ",") - 1)))
If IsDate(firstdate) = True Then
TxtIssued = DateValue(firstdate)
End
seconddate = Trim(Mid(Data, (InStr(Data, ",") + 1)))
If IsDate(seconddate) = True Then
TxtServed = DateValue(seconddate)
End If

End Sub


" wrote:

On Dec 4, 12:45 pm, Joel wrote:
Try this code

Sub getfields()

Data = Range("A1")

firstname = Trim(Left(Data, (InStr(Data, ",") - 1)))
Data = Mid(Data, (InStr(Data, ",") + 1))
lastname = Trim(Left(Data, (InStr(Data, ",") - 1)))
Data = Mid(Data, (InStr(Data, ",") + 1))
mother = Trim(Left(Data, (InStr(Data, ",") - 1)))
mothernumber = Val(Trim(Mid(Data, (InStr(Data, ":") + 1))))
Data = Mid(Data, (InStr(Data, ",") + 1))
mychild = Trim(Left(Data, (InStr(Data, ",") - 1)))
Data = Mid(Data, (InStr(Data, ",") + 1))
firstdate = DateValue(Trim(Left(Data, (InStr(Data, ",") - 1))))
seconddate = DateValue(Trim(Mid(Data, (InStr(Data, ",") + 1))))

End Sub



" wrote:
here is the code i was using to split the variable, however
the information is put together like this :


FirstName,Lastname,Mother:1,Mychild,10/12/2007 ,10/11/2007


now the problem im having is when it gets to the date, it doesnt
return the date so TxtServed and TxtIssued are still blank


vntX = Split(strToSplit, ",")


If intChoose = 0 Then
SplitMe = vntX(0) & "," & vntX(1) ' First Name Last Name
ElseIf intChoose = 2 Then
SplitMe = vntX(2) ' MoFa CBo Box
ElseIf intChoose = 1 Then
TxtFirstName = vntX(0) ' First Name
TxtLastName = vntX(1) ' Last Name
CBOMoFa = vntX(2) ' parent type
TxtChild = vntX(3) ' Childs Name
If UBound(vntX) = 4 Then
TxtIssued = vntX(4) ' issued
Else
TxtIssued = ""
End If
If UBound(vntX) = 5 Then
TxtServed = vntX(5) ' served
Else
TxtServed = ""
End If
End If- Hide quoted text -


- Show quoted text -


the problem with this is that
either 1 or both of these might be empty, and im not that familiar
with using ubound i actually had someone help me with this a while
back on here.. so if possible could it be explained, or help me to
figure it out im currently looking through forums online to find out
exactly how to use it :|
TxtIssued = DateValue(Trim(Left(data, (InStr(data, ",") - 1))))
TxtServed = DateValue(Trim(Mid(data, (InStr(data, ",") + 1))))



All times are GMT +1. The time now is 06:09 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com