473,404 Members | 2,170 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

String textbox question

AMP
Hello,
I want to add some variables to a string and this isnt working.
textBox1.Text="'BSL version='+ bslVerHi[0]+ bslVerLo[0]";
What am I doing wrong?
Thanks
Mike

Sep 17 '06 #1
5 2295
You likely have an issue with the conversion of your variables to string
format.
One method you might use is the use of the string.format command.
See this example from MSDN help.

Notice how they parameterize the variables... {0:C} means the first
varialble is formatted as Currency.

Visual Basic Copy Code
' This code example demonstrates the String.Format() method.
' Formatting for this example uses the "en-US" culture.

Imports System
Imports Microsoft.VisualBasic

Class Sample
Public Enum Color
Yellow = 1
Blue = 2
Green = 3
End Enum 'Color

Private Shared thisDate As DateTime = DateTime.Now

Public Shared Sub Main()

' Store the output of the String.Format method in a string.
Dim s As String = ""

Console.Clear()

' Format a negative integer or floating-point number in various ways.
Console.WriteLine("Standard Numeric Format Specifiers")
s = String.Format("(C) Currency: . . . . . . . . {0:C}" & vbCrLf & _
"(D) Decimal:. . . . . . . . . {0:D}" & vbCrLf & _
"(E) Scientific: . . . . . . . {1:E}" & vbCrLf & _
"(F) Fixed point:. . . . . . . {1:F}" & vbCrLf & _
"(G) General:. . . . . . . . . {0:G}" & vbCrLf & _
" (default):. . . . . . . . {0} (default = 'G')"
& vbCrLf & _
"(N) Number: . . . . . . . . . {0:N}" & vbCrLf & _
"(P) Percent:. . . . . . . . . {1:P}" & vbCrLf & _
"(R) Round-trip: . . . . . . . {1:R}" & vbCrLf & _
"(X) Hexadecimal:. . . . . . . {0:X}" & vbCrLf, _
- 123, - 123.45F)
Console.WriteLine(s)

' Format the current date in various ways.
Console.WriteLine("Standard DateTime Format Specifiers")
s = String.Format("(d) Short date: . . . . . . . {0:d}" & vbCrLf & _
"(D) Long date:. . . . . . . . {0:D}" & vbCrLf & _
"(t) Short time: . . . . . . . {0:t}" & vbCrLf & _
"(T) Long time:. . . . . . . . {0:T}" & vbCrLf & _
"(f) Full date/short time: . . {0:f}" & vbCrLf & _
"(F) Full date/long time:. . . {0:F}" & vbCrLf & _
"(g) General date/short time:. {0:g}" & vbCrLf & _
"(G) General date/long time: . {0:G}" & vbCrLf & _
" (default):. . . . . . . . {0} (default = 'G')"
& vbCrLf & _
"(M) Month:. . . . . . . . . . {0:M}" & vbCrLf & _
"(R) RFC1123:. . . . . . . . . {0:R}" & vbCrLf & _
"(s) Sortable: . . . . . . . . {0:s}" & vbCrLf & _
"(u) Universal sortable: . . . {0:u} (invariant)" &
vbCrLf & _
"(U) Universal sortable: . . . {0:U}" & vbCrLf & _
"(Y) Year: . . . . . . . . . . {0:Y}" & vbCrLf, _
thisDate)
Console.WriteLine(s)

' Format a Color enumeration value in various ways.
Console.WriteLine("Standard Enumeration Format Specifiers")
s = String.Format("(G) General:. . . . . . . . . {0:G}" & vbCrLf & _
" (default):. . . . . . . . {0} (default = 'G')"
& vbCrLf & _
"(F) Flags:. . . . . . . . . . {0:F} (flags or
integer)" & vbCrLf & _
"(D) Decimal number: . . . . . {0:D}" & vbCrLf & _
"(X) Hexadecimal:. . . . . . . {0:X}" & vbCrLf, _
Color.Green)
Console.WriteLine(s)
End Sub 'Main
End Class 'Sample
'
'This code example produces the following results:
'
'Standard Numeric Format Specifiers
'(C) Currency: . . . . . . . . ($123.00)
'(D) Decimal:. . . . . . . . . -123
'(E) Scientific: . . . . . . . -1.234500E+002
'(F) Fixed point:. . . . . . . -123.45
'(G) General:. . . . . . . . . -123
' (default):. . . . . . . . -123 (default = 'G')
'(N) Number: . . . . . . . . . -123.00
'(P) Percent:. . . . . . . . . -12,345.00 %
'(R) Round-trip: . . . . . . . -123.45
'(X) Hexadecimal:. . . . . . . FFFFFF85
'
'Standard DateTime Format Specifiers
'(d) Short date: . . . . . . . 6/26/2004
'(D) Long date:. . . . . . . . Saturday, June 26, 2004
'(t) Short time: . . . . . . . 8:11 PM
'(T) Long time:. . . . . . . . 8:11:04 PM
'(f) Full date/short time: . . Saturday, June 26, 2004 8:11 PM
'(F) Full date/long time:. . . Saturday, June 26, 2004 8:11:04 PM
'(g) General date/short time:. 6/26/2004 8:11 PM
'(G) General date/long time: . 6/26/2004 8:11:04 PM
' (default):. . . . . . . . 6/26/2004 8:11:04 PM (default = 'G')
'(M) Month:. . . . . . . . . . June 26
'(R) RFC1123:. . . . . . . . . Sat, 26 Jun 2004 20:11:04 GMT
'(s) Sortable: . . . . . . . . 2004-06-26T20:11:04
'(u) Universal sortable: . . . 2004-06-26 20:11:04Z (invariant)
'(U) Universal sortable: . . . Sunday, June 27, 2004 3:11:04 AM
'(Y) Year: . . . . . . . . . . June, 2004
'
'Standard Enumeration Format Specifiers
'(G) General:. . . . . . . . . Green
' (default):. . . . . . . . Green (default = 'G')
'(F) Flags:. . . . . . . . . . Green (flags or integer)
'(D) Decimal number: . . . . . 3
'(X) Hexadecimal:. . . . . . . 00000003

"AMP" <am******@gmail.comwrote in message
news:11**********************@m7g2000cwm.googlegro ups.com...
Hello,
I want to add some variables to a string and this isnt working.
textBox1.Text="'BSL version='+ bslVerHi[0]+ bslVerLo[0]";
What am I doing wrong?
Thanks
Mike

Sep 17 '06 #2
Are your variables of type string?

--
HTH,

Kevin Spencer
Microsoft MVP
Chicken Salad Surgery

What You Seek Is What You Get.

"AMP" <am******@gmail.comwrote in message
news:11**********************@m7g2000cwm.googlegro ups.com...
Hello,
I want to add some variables to a string and this isnt working.
textBox1.Text="'BSL version='+ bslVerHi[0]+ bslVerLo[0]";
What am I doing wrong?
Thanks
Mike

Sep 17 '06 #3
AMP,

In my idea you have to set the last quote behind the last single quote.

(If I understood well what you want)

Cor

"AMP" <am******@gmail.comschreef in bericht
news:11**********************@m7g2000cwm.googlegro ups.com...
Hello,
I want to add some variables to a string and this isnt working.
textBox1.Text="'BSL version='+ bslVerHi[0]+ bslVerLo[0]";
What am I doing wrong?
Thanks
Mike

Sep 18 '06 #4
AMP <am******@gmail.comwrote:
I want to add some variables to a string and this isnt working.
textBox1.Text="'BSL version='+ bslVerHi[0]+ bslVerLo[0]";
What am I doing wrong?
That will display the literal string:

BSL version='+ bslVerHi[0]+ basVerLo[0]

because that's what's inside the double quotes, which means it's all
part of a string literal. I suspect you meant:

"BSL version"+bslVerHi[0]+bslVerLo[0];

That would give something like

BSL versionxy

(if bslVerHi[0] is "x" and bslVerLo[0] is "y".

Is that what you wanted?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Sep 18 '06 #5
AMP
THANKS(again)
Mike
Jon wrote:
AMP <am******@gmail.comwrote:
I want to add some variables to a string and this isnt working.
textBox1.Text="'BSL version='+ bslVerHi[0]+ bslVerLo[0]";
What am I doing wrong?

That will display the literal string:

BSL version='+ bslVerHi[0]+ basVerLo[0]

because that's what's inside the double quotes, which means it's all
part of a string literal. I suspect you meant:

"BSL version"+bslVerHi[0]+bslVerLo[0];

That would give something like

BSL versionxy

(if bslVerHi[0] is "x" and bslVerLo[0] is "y".

Is that what you wanted?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Sep 18 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Grisha0 | last post by:
Hi, i've got a little question. I'd like to create an object for example TextBox normaly it'd like look like this: TextBox my_Object = new TextBox(); but i'd like to get the name of the...
10
by: Ricardo | last post by:
How can I make a insert sql string to insert direct in a table(not a dataset) using the textbox.text propert??
32
by: tshad | last post by:
Can you do a search for more that one string in another string? Something like: someString.IndexOf("something1","something2","something3",0) or would you have to do something like: if...
12
by: James Norton-Jones | last post by:
Hi, Am I trying to hold the data of a DataGrid in a label so that when the form is reposted the DataGrid can be repopulated. The problem I am having is that I don't understand how to get the...
4
by: http://www.visual-basic-data-mining.net/forum | last post by:
Hi Does anyone know how to stay connected to the server and at the same time i can pass the string to and from the module to the form..... What I want: I put the connection at the...
5
by: poldoj | last post by:
Hi all, I have a simple question. I must adding the content of a textbox, that is actually a string to a variable that his datatype is an integer. Example, I declare a public integer variable then...
2
by: Cerebrus99 | last post by:
Hi, Say, I have 20 textboxes on my form placed in different panels, groupboxes. The names of the textboxes range from "TextBox1" to "TextBox20". I want to get a reference to each textbox using...
4
by: Randy | last post by:
My situation is that I have a form on which a number of textboxes and comboboxes are added dynamically based on interaction with the user. As these controls are added, they are given names based on...
4
by: =?Utf-8?B?cm9kY2hhcg==?= | last post by:
hey all, is there a way to find a textbox id with a search string in the code-behind? thanks, rodchar
1
by: dantz | last post by:
Hi everyone, I have a textbox which is multiline and wordwrap is true. I did not set any scrollbar because I want to show it manually (using different buttons) The textbox will sometimes have...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.