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!

Help with string conversion

Status
Not open for further replies.

kloner

Programmer
May 15, 2000
79
AU
Hi all :

I want to somehow split a string ("12,43") and set two variables.

eg.

Dim m_strTemplate As String
Dim m_intTemplateID As Integer
Dim m_intColourSchemeID As Integer

m_strTemplate = "12,4"

' Split up the TemplateIDs
m_intTemplateID = "12"
m_intColourSchemeID = "4"

How do I do this?
kloner


 
m_intTemplateID = CInt(Left$(m_strTemplate, InStr(m_strTemplate, ",") - 1))

m_intColourSchemeID = CInt(Right$(m_strTemplate, Len(m_strTemplate) - InStr(m_strTemplate, ",")))

David Paulson

 
Code:
Dim aryStr() as string
aryStr = Split(m_strTemplate,",")
If Ubound(aryStr) < 1 then 
    Redim Preserve aryStr(1)  
End if
m_intTemplateID = aryStr(0)
m_intColourSchemeID = aryStr(1)
 
you first take a string
count the no of characters in it
after that check from first character to end character
if the character match &quot;,&quot; then split in to the different
names

'prograM STARTS
' first is the first number i.e. string
' second is the second string

dim first as string
dim second as string
dim actual as string
dim i as integer
dim n as integer
actual=&quot;12,13&quot;
n= len(actual)
first=&quot;&quot;
for i = 1 to n
if mid$(actual,i,1) = &quot;,&quot; then
second = mid$(actual,i+1,n-i)
exit for
else
first=first+mid$(actual,i,1)
endif
next i

' it works succesfully pl inform me shanmugham@hotmail.com






 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top