|
-
Oct 21st, 2004, 02:35 AM
#1
Thread Starter
Frenzied Member
How to format strings so that they go into lstBox neater.
Hi there,
How can i format a string so that it all a fixed length of character so that i can put them in a listbox. I have tried substring, but if the length of the word is less than the specfied end length, it returns an error.
any ideas folks ?
Last edited by dinosaur_uk; Oct 25th, 2004 at 09:05 AM.
-
Oct 21st, 2004, 03:31 AM
#2
Do a check for length first. If above value x, then use substring, else leave as it is.
Show your code.
Also, tell us why you don't want to show the entire string in the listbox... other than it appearing 'neat'.
-
Oct 21st, 2004, 03:36 AM
#3
Thread Starter
Frenzied Member
Oh i have three strings, like number, description etc etc
usually the description is too long or too short, so the next variable looks terrible...
-
Oct 21st, 2004, 03:43 AM
#4
OK, show your code so far.
-
Oct 21st, 2004, 06:21 AM
#5
Hyperactive Member
Hi Mendhak, hi Dinosaur......I'm not sure to understand what you want to obtain, dear Dinosaur, but I suggest you to have a look to padright and padleft methods, perhaps thay can be useful for you, if not, sorry.
Live long and prosper (Mr. Spock)
-
Oct 21st, 2004, 06:25 AM
#6
Thread Starter
Frenzied Member
(vbcode)
Private Sub btnDcName_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDcName.Click
'This is for the list of DC channel names.
lstDcName.Items.Clear()
For intchannel = 1 To 256
GetDCData(ThreadId, intchannel, valChannel) 'gets DC data and outputs the value to valChannel
GetDCName(ThreadId, intchannel, dcname, 1) 'gets DC name and outputs it to dcname
'This if loop is to format the list to make it look tidier
If intchannel.ToString.Length = 1 Then
lstDcName.Items.Add(intchannel & " : " & dcname) 'Adds the items into the array.
ElseIf intchannel.ToString.Length = 2 Then
lstDcName.Items.Add(intchannel & " : " & dcname) 'Adds the items into the array.
Else
lstDcName.Items.Add(intchannel & ": " & dcname) 'Adds the items into the array.
End If
'Puts the entire DC channel namelist into an array
DcArray(intchannel) = valChannel
Next
(/vbcode)
-
Oct 21st, 2004, 06:36 AM
#7
Originally posted by dinosaur_uk
If intchannel.ToString.Length = 1 Then
lstDcName.Items.Add(intchannel & " : " & dcname) 'Adds the items into the array.
ElseIf intchannel.ToString.Length = 2 Then
lstDcName.Items.Add(intchannel & " : " & dcname) 'Adds the items into the array.
Else
lstDcName.Items.Add(intchannel & ": " & dcname) 'Adds the items into the array.
End If
Here, you are simply taking the numbers, converting to string, and adding to a listbox. And all conditions are doing the same thing. Is this the problem? Which part of this poses the problem to you? three digit numbers?
-
Oct 25th, 2004, 02:09 AM
#8
Thread Starter
Frenzied Member
This is me trying to format the index. The problem is that the strings pulled from a data file is of a variable length... and i am not sure how to format it...
-
Oct 25th, 2004, 02:15 AM
#9
Here's what I did, I created an array of strings of varying lengths, and added them to the listbox like so:
VB Code:
Dim strArr(6) As String
strArr(0) = "34"
strArr(1) = "2349823"
strArr(2) = "3"
strArr(3) = "af2323"
strArr(4) = "3asdf4"
strArr(5) = "23ash49823"
strArr(6) = ".."
Dim intCount As Integer
For intCount = 0 To strArr.GetUpperBound(0)
If strArr(intCount).Length > 3 Then
ListBox1.Items.Add(strArr(intCount).Substring(0, 3) & "...")
Else
ListBox1.Items.Add(strArr(intCount))
End If
Next
Is this what you were looking for? If not, post a snapshot of what you have, and an image of what you'd like to have.
-
Oct 25th, 2004, 09:05 AM
#10
Thread Starter
Frenzied Member
All sorted !
Thank you very much, you are a VB Angel, bringing me to VB heaven....
-
Oct 26th, 2004, 12:09 AM
#11
Re: All sorted !
Originally posted by dinosaur_uk
Thank you very much, you are a VB Angel, bringing me to VB heaven....
You flirt. :blush:
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|