|
-
Sep 25th, 2002, 01:36 PM
#1
Thread Starter
Addicted Member
.Net "String" equivalent
How do you do the following in VB.NET:
Dim mystring as string * 25
I thought it may be
Dim mystring as new string("",25)
But I think I may be mistaken..
Thanks
Tom
-
Sep 25th, 2002, 01:43 PM
#2
I think
Dim mystring As New String("",0,25)
will work
-
Sep 25th, 2002, 01:47 PM
#3
Thread Starter
Addicted Member
Ouch
Tried that,
Dim SDEPT As New String("", 0, 25)
Got:
An unhandled exception of type 'System.ArgumentOutOfRangeException' occurred in HelloWorld.exe
Additional information: Index was out of range. Must be non-negative and less than the size of the collection.
Any more ideas?
-
Sep 25th, 2002, 01:53 PM
#4
<VBFixedString(25)> Public buffer As String
-
Sep 25th, 2002, 02:12 PM
#5
Thread Starter
Addicted Member
Thanks But..
Dander,
Thanks, I should have seen that in the MSDN..
Still not quite "right"
in VB 6.0:
Dim stringa As String
Dim stringb As String * 25
stringa = "TEST"
stringb = stringa
MsgBox " ' " & stringb & " ' "
The message box would show something like:
'TEST '
Showing the whole 25 positions.
Doing the same .Net I am still getting:
'TEST'
Even with the declared length.
Bummer I need to get it as such for some keyed reads..
Tom
I tried it, and when I did a message box on it:
-
Sep 25th, 2002, 02:14 PM
#6
Thread Starter
Addicted Member
Darn display!
Dander
The "TEST" example did not display right..
In VB 6.0 I would see "TEST" with the balance of the 25 positions in the msgbox
-
Sep 25th, 2002, 02:20 PM
#7
Well I dont know then..
-
Sep 25th, 2002, 02:23 PM
#8
Thread Starter
Addicted Member
Thanks
Thanks for the help anyway, I still "learned something"
Maybe someone else can find the missing clue?
Tom
-
Sep 25th, 2002, 02:27 PM
#9
perhaps tell us what you are trying to do that you need fixed length strings. There maybe another way
-
Sep 25th, 2002, 02:27 PM
#10
Thread Starter
Addicted Member
-
Sep 25th, 2002, 02:29 PM
#11
LOL. Its ok.
-
Sep 25th, 2002, 02:37 PM
#12
Thread Starter
Addicted Member
Well
For one thing I got data in Oracle tables that have trailing
spaces:
fieldx = "somevalue<SPACE><SPACE><Etc>"
so when I do a SQL command I need the key value to reflect that fact.
The other thing I was trying to do is to create a menu selection in a list box with the menu "option number" portion of the string I am adding to the listbox as being the current index value. I want the index value to be part of concatenated field of fixed length 2 padded left to line it up:
dim str_optionnumber as string * 2
dim str_text as string
dim str_combined as string
dim index as integer
index = 1
str_text = "Reports Menu"
str_optionnumber = index
str_combined = str_optionnumber.padleft(2) & "." & space(1) & str_text
listbox1.items.add(str_combined)
result:
1. Reports Menu
add the reset:
2. blah
"
"
10. blah
the menu selections would be in alignment.
If any other ideas please let me know; this IS tedious!
-
Sep 25th, 2002, 02:40 PM
#13
hmm..well perhaps look into the stringbuilder class. I think you can set some fixed length there..dont know if it will accomplish hat you need though.
-
Sep 25th, 2002, 02:54 PM
#14
arg stringbuilder doesnt work either. I tried it.
-
Sep 25th, 2002, 03:26 PM
#15
Member
There are no fixed lentgh strings in .net
Try PadRight.
Dim strW As String
strW = "A"
strW = StrW.PadRight(25," ")
MessageBox.Show(Len(strW))
The Length of strW should be 25.
Harold Hoffman
-
Sep 25th, 2002, 03:29 PM
#16
yeah, but the VBFixedString attribute is supposed to emulate it. but it doesnt work.
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
|