a listbox problem...???

denfor

Newcomer
Joined
Dec 21, 2004
Messages
11
i use visual c++.NET 2003. well,in rows of listbox i have such looking:

12,22,34
13,44,55
11,2,33

and goes down.while the form is working and after u select a row in the listbox,i need a button to make this converstion:
(assumpt 1st row is chosen in listbox)
a=12,b=22,c=34
or (assumpt 2nd row is chosen in listbox)
a=13,b=44,c=55
.
.
.
the numbers are not fixed numbers,in each calculation u open the form,they change with different inputs.so basically,i need to take the numbers separated by comma in a row of the listbox.how can i do that?what code i need to write under the button? :o

OR instead of writing the numbers seperated by comma into a listbox,where can i store such data ( but 3 of them in one row) ? take care everyone,have a nice day.
 
So...If I understand correctly the listbox text is in a csv format and you want to separate the text into values.

Visual Basic:
        If ListBox1.SelectedIndex >= 0 Then
            Dim value() As String
            Dim values As String = ListBox1.SelectedItem
            value = values.Split(",")
            MessageBox.Show(value(0))
        End If

This returns a String value
Is this what you are looking for?
 
u r right coldfusion 244 ! thats what i need.and diverdan,u understyand correctly but i dont knbow vb.net.if u know,can u say the code for vc++.NET 2003 ?? thank u everyone,take care.
 
Adding on top of diverdan's code...

Visual Basic:
If ListBox1.SelectedIndex >= 0 Then
     Dim value() As String
     Dim a,b,c as Integer
     Dim values As String = ListBox1.SelectedItem
     value = values.Split(",")
     a = int.parse(value(0))
     b = int.parse(value(1))
     c = int.parse(value(2))
End If

Forgive me, but I don't have VS on this computer, nor do I program in VB, but that should work. You are just going to take the string value that you have from splitting the values and use int to parse it to an actual integer(since you only gave integer values in your examples, i assumed they will always be integers).
 
or
a = Convert.ToDouble(value(0))
etc.

point is that I already showed denfor how to do it...and it doesn't seem he understood this. Or maybe he's looking for some vc++ code.....I'm not sure if vc++ uses the Split function but...

denfor, what you need to do is split the listboxes selected text into an array using "," as the deliminator. As you can only do this in a string format, you'll need to convert the value string into whatever format you need.
 
thanks

thank u guys.well,i am searching for "split " command and its usega in vc++.i understand what u mean but i just try to find a suitable vc++.net code and i have to look for split functionality.thank u for your help.i will announce when i solve the problem.maybe someone also need the similiar code.have a nice day.
 
There is no 'Split' function in VC++. You can use MFC and get CString's which have more functionallity than Strings which should help you out more. But, you can go for the easy approach and just loop until you find a ',', set the index and do a substring. then you could attempt to cast it to an integer/double/etc after that, don't know how well it'll work.
 
Back
Top