Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    Visual Basic




Convert String Into Integer Or Single


Maybe a stupid question. but I just forget, I'm just restarted programming after a long time, and I forgot many things, but it's slowly all coming back.

So the question is to convert the contence of a txt into a integer or single or something like that to calculate with it..


thank you very much to the best




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Is There A Way To Convert A String To Integer?
is there a way to convert a string to integer?
for example "23" -> 23?
thnaks
peleg

Convert String To Integer
I have two variables

1) the value is "12" (as String)
2) the value is 12 (as Integer)

I need to compare them and see if they are equal or greater or lesser.

I know if I just needed to see if they were essentially equal I could use "like".
However that doesnt cover the whole deal because I know of no way to see if they are greater or lesser ie suppose they were "12" and 6

They are always numbers even if VB thinks they are strings. I never have alphabetical results.

I either need to know how to do an equal, greater, lesser comparison as the variables stand ie integer to string

or a way to turn the string to an integer.

PS If anyone is wondering why I have a numeric string variable its because I parsed it out of an alphanumeric variable.


Thanks Robert

Convert String To Integer
Hi guys,

Suppose I have a .txt file that contains team names like the following:

Arsenal
Liverpool
Leeds
Chelsea
Everton

How could I edit this so that when I extract the data, instead of extracting the team name, I extract the following:

1
2
3
4
5

To obtain the teams normally, I would use something like this:

dim strTeam() as string
dim count as integer

Open App.Path + "/Teams.txt for input as #1
Do While not EOF(1)
Input #1, strTeam(count)
count = count + 1
Loop

Close #1

Cheers for any help,

MiniMe

Convert A String To An Integer
Hello,
How can I convert a string to an integer ?

Best Regards

bonj98

How To Convert A String In A Integer
dim subtotal as integer
dim strsql as string

strsql = "SELECT SUM(Price) FROM RECEIPT"
strsql = Subtotal


what´s wrong?

Convert String To Integer
is there an easy way to convert a string to an integer?

Convert String To Integer?
IS this possible in vb6?

In delphi you can do Integer(string) and it works..


Thank you.

Convert String To Integer
i am reading in a number from a textfile, so it will be a string.

how can i convert that number to an integer, as i will need it in a for loop

Convert String To Integer
hi, there

can anyone help me?

i have a form with a Find command button. when click the Find button, user is requested to key-in the name of the particular person. however, in Access the data type for Name column is Text, so how to i convert string to interger in order to look for that particular person.

thx.

Convert A String To Integer
convert a string to integer

how do i convert a string to integer ???

How To Convert An Integer To A String
Does anyone know how to take an integer value and convert it to a string value?

Thanks,

Convert String To Integer
I do this:

TXT_total.text=TXT_1.text + TXT_2.txt

TXT_1 = 1
TXT_2 = 2

The command do that : 12
but I want that : 3

I dont want to put a VARIABLE if possible ..
Did someone know how ??
like:

dim TXT_total.text as integer

Convert A String To A Integer In VB6
Hello,

I am pulling a date from a text file and it is a string - "20060209".

I need to format this date into 02/06/2006.

I use this lline of code -
tillDte = Format(tillDte, "mm/dd/yyyy")

However this gives me an overflow error run-time 6.

Any ideas on how I can format this?

Thanks

Convert String To Integer?
I am needing to read a list of 30 #s from a txt file. I am able to read the file and dim the variable as a string. How do I thne get that string to become data for an array? Please let me know if tha tmakes no sense, because it barely does to me either.

Convert An Integer Into A String
how do i convert a number into a text?

thank you

Convert Integer To String
In Excel VBA how do you convert an integer into a string? I've tried:

Code:RowNum = Convert.tostring(i)

Code:i.tostring()

Any suggesstions?

How To Convert String To Integer In VB6?
As the title, how could I convert the String into Integer in VB6?

Say:

Dim str As String
Dim num As Integer

str = "12345"

How could I set the integer value to num (12345) here ?

Thanks!
Jim Cheng

Convert Integer To String
How does one convert from an integer to a string?

ex) Dim i as Integer
i = 1 //convert i to a string????

I'm,
notacoder

VBA Constants - Convert From String To Integer
Microsoft use a heap of constants (eg: acForm, xls3dBarGraph etc) Each of these "strings" is actually an integer contstant.

I have a table of graph constants that are the string "name" of the contstant (eg: xls3DBarGraph) and I want to programatically convert them to their equiv INTEGER number.

In Debug window, you can type ?xl3DColumnClustered and press enter, you get the number of the constant (54 in this example). Does VBA have a built in function that converts a string of "xl3DColumnClustered" to the equiv number or 54?

ie: in debug:
?"xl3DColumnClustered" <enter> returns the string "xl3DColumnClustered"

where as
?xl3DColumnClustered <enter> returns the number 54

I need to do the second case programatically if I can.

Thanks in advance

Convert Month As String To Integer
Does anyone know of a function in VBA that converts a month as a string (eg 'September') to a month as an integer (9)? I can do it with this defined function:


Code:
Function mymonth(mnthstring As String)
Dim i As Integer
mymonth = 0

For i = 1 To 12
If Format(DateSerial(1, i, 1), "mmmm") = mnthstring Then mymonth = i
Next i

End Function

but figured VBA would most likely have a function that does it already (Making my code much sexier!)

Any info would be great! Cheers Guys!

*edit* Sorry about the double post, my connection timed out and I didn't think it had posted. My Bad!

Convert String To Integer In 2d Array
I have a 2d array that is loaded from a fixed length file.
e.g
array(0, 0) = "1 "
array(1, 0) = "35 "

I need to convert this column of the array from string to integer so I can compare the value of the array with compare symbols (<,>,=,etc...)

As always thanks for the help.

How To Convert MSComm String To Integer
I am a VB6 Newbie and I'd like some help in coverting a stream of serial data from MSComm (Com1) to integer. The serial data stream comes in at a slow rate from a industrial PLC. Multiple 16-bit values are transmitted from the PLC to my PC as a constant stream of bytes as the machine runs.

The serial data goes into "strBuffer"
Dim strBuffer As String

Since the industrial PLC is sending 16-bit data values, I believe I need to extract multiple strings of length=2, convert them into integers and then do my math. (I can always synch the data on 16b boundaries so that's not an issue).

As a test I have tried the following and it does not work.
Dim ZZZ as integer
Dim ZS as string

ZS = (Mid(strBuffer, 1, 2))
ZZZ = CInt(ZS) *** Always generates a Error 13 Type Mismatch.

I'm so lost on how to resolve this. I've gone round and round for hours. Please pass on your suggestions. Thanks Robo

Convert String To Integer/number
Can anyone help me in converting string to integer/number in vbscript?

Convert String To Single
Hello code gurus :-)

I've got string containing four bytes that represent float value in SINGLE format. How do I get the value they represent?

In C it would have been very easy. You would place this string into memory and just typecast it. Are there any facilities in VB that provide similar service? Can I use pointers or typecasting or something?

I have got some strange algorithm from a guy who was working on the project before me but it involves several pages of code and is not very optimal. Is there some simple way perhaps?

Thank you a lot...

C Programmers.. How To Convert A Float Or Integer Into A String..
want to convert a given number.. either a float or an integer and convert it to a string in order to test if it contain any alphabet coz the program must only accept digits and not alphabets or other characters..

if there's any other ideas on how to limit the input of the user to digits only.. it would be a great help.. tnx.. i'm on the tip of a deadline..

Edit: I moved this thread due to the title...even though it's not clear that whether you're using C or just appealing to C programmers for help with VB!

Convert String To Integer... Really Easy But Im Dumb
How do you convert a string to a variable?? i really need to know, and i am too stupid to figure this one out.

How To Convert A String(charand Number) To Integer?
can anyone help me on how to convert a string to integer?

well i already wrote a script that converts it but my code only converts numbers but not the characters...what i need to do is convert both the char and numbers...

here is my code..
Dim StringValue_1 As String
Dim IntValue_1 As Integer
Dim StringValue_2 As String
Dim IntValue_2 As Integer

StringValue_1 = "12345edf"
IntValue_1 = Val(StringValue_1)

StringValue_2 = "6789abc"
IntValue_2 = Val(StringValue_2)

the IntValue_1 only shows 12345 and IntValue_2 only shows 6789,they did not the characters..is there a way to do it?tnx

How To Convert Empty String To Single Data Type
I have an application in which user gives input values to textboxes. The given input values are then stored to parameters for further use. I earlier used Val function to read the values to parameters, but now I'd like to use CSng function for international reasons. What should I do with empty textboxes, containing empty strings? CSng function gives "Type mismatch" error when reading an empty textbox. I wouldn't want to use IsNumeric function with every textbox before reading the value with CSng function

Earlier I had:
parameter = Val(txtInput.Text)
txtInput.Text = "" => parameter = 0

Now I'd like to have:
parameter = CSng(txtInput.Text)
txttInput.Text = "" => "Type mismatch"

I don't want to have:
If IsNumeric(txtInput.Text) = True Then parameter = CSng(txtInput.Text)

How To Convert From Integer/long Integer To Binary ?
How to convert from integer or long integer to binary in Visual Basic,
for example : 9568 to 10010101100000
and how to convert back from binary to integer or long integer,
for example : 10010101100000 to 9568.

Please help.
dev.

Integer To Single
I know there's a funtion to make make some value an integer:

Code:
dim X as integer
t = 100
X = int(t)

how do I do that with a single?

Code:
dim x as single
t = 100
'something like this?
x = sng(t)

Integer - %; Long - &&; Single - ?? Double - ??
What are abbreviations for data types?
I know:
integer - %;
long - &;

I would like to know:
single - ??
double - ??
string - ?? (if i recall it was $, right?)
variant - ??

Casting Single Precision Number To 32 Bit Integer
I am trying to do what in C is termed as cast a single precision number into a 32-bit integer (Long in VB). I have tried searching the web for code examples but I cannot seem to find any. An example of what I Am trying to do is:

if my floating point number is 1.0, the 32 bit number I want to output is 3F800000.

If anyone has a source example of how to do this, I would really appreciate it.

Validation Between Integer And Floating Point(single)
hi,
does anone know how to validate/check between a integer(without the '.') and Single(floating point with '.') data type? eg. i have a text box for user to enter a value, how to check what type of value(integer or single) does the user enter without check it manually as we treat it as string?

Thanks for help.

Converting String To Integer And Integer To String
There are two ways of doing this, but I was wondering which was was more efficient or does it not matter?


VB Code:
Dim sStr As StringDim iInt as Integer 'This works finesStr = 355iInt = "355" 'This also workssStr = Str(355)iInt = Val("355")


Also is there ever a time where you would actually need to use the second method over the first?

Tool To Detect Implicit Conversions (e.g. Integer = Single * Byte)
Hi,

I'm looking for a tool to detect implicit conversions of variables like integer = single * byte.
Does anybody have an idea how to detect those?

Thanks a lot!

Convert To Integer
Well I;m making a network blackjack game and when I deal a hand, the client gets a message saying "You cards are 6S and KH" or whatever their hand is.

I want to, for blackjack purposes, make the computer also read that as 16.

"Your cards are 7D and 9H" also needs to read as 16

since these are in string I'm not sure how i would do this. Thanks.

How To Convert Integer To Kb,mb Etc
Hi Guys,

I have a filesize field in my database which is of type Integer. How can I convert that integer to kilobytes or megabytes etc.

How To Convert Integer To Time?
I have a textbox where users input time in military time. For example

900
1200
1400
2200

How to I convert this to a time and have vb work with it? For example, the code below should know that i want "6/1/06 9:00am"

Code:
dim date1 as date
dim time1 as date
dim datetime as date

date1 = "6/1/06"
time1 = cdate(textboxt.text) 'someone typed "900" in the textbox
datetime = date1 + time1 'should give me 6/1/06 9:00am
'later in my code i will add or subtract this datetime to get number of hours in between
thanks.

How To Convert Integer To Char?
I have a c++ function that convert an int type to char type, and I need to write a similar one in VB.
Can anyone please help me?

The c++ function is:

template <class T> void ConvertToChar(char* buff,T item)
{
int itemSize = sizeof(item);

for(int i=0;i<itemSize;i++)
{
buff[((itemSize-1) - i)] = char(item);// extract each byte, starting with hi byte
item >>= 8;
}
}


The call to the function is:

short mMsgLength;
char buff[2];

mMsgLength = fGetMsgLength(); // returns unsigned short
ConvertToChar(buff,mMsgLength);


Thanks,
Kruvi

Convert Time To Integer
how can I convert Time to Integer or String?

Convert Integer To Binary Hex Value
Hi
I have a variable which is for sake of argument the Size of a File in Bytes. The value is an integer

I wish to convert this value into a binary string so that I can transmit it via the ethernet winsock control.
Basically I want to convert the whole number using something like the CHR function. However I also need the number to be padded to 'n' bytes....


Code:

FileSize = 123456
n = 6

DataToSend = convert(filesize,n) ' <-- this is the function Im stuck with

The result would be DataToSend = 0x 01E240

Any ideas / suggestions?

Cheers

Pete

Convert Text To Integer
How do you convert a text into integer with just sql manipulation? I couldn't change the structure of the table, but i need my data to be organized in order ( by their item number) . how would you do that ? THe item number is text but the data it holds is an integer.
Similarly, how do you convert a text into date . I need my data to be organized by their dates as well.
database is access 97.

Convert Integer To Datetime In Vb...
Ok, SQL allows for us to do a conversion of integer to datetime...ex:

DECLARE @INT DECIMAL(19,5)
DECLARE @NewDate DECIMAL(19,5)
DECLARE @CorrectedDate datetime

SET @INT=((1095969016.00000-18000.00000)/86400.00000)+ 25567.00000
PRINT @INT
SET @NewDate = @INT --+ 25569.00000
SET @CorrectedDate = CONVERT(datetime, @NewDate, 121)
PRINT @CorrectedDate

The problem is when you start trying to do this in Visual Studio/Reporting Services...The convert class does not allow for a conversion from Int to Datetime, in fact the only conversion allowed is from string. Anyone every tried to convert an time integer in vb? BTW, the integer used in this example is actually the number of seconds between Jan 1, 1970 and present. When you divide by the 86400 the remainder is the time and the int is the date. Thanks for you help in advance...

Convert A Integer To Date
Hy to All

the problem is this

I have the day of a month
"
VB Code:
dim day as integer = Date.DaysInMonth(dt.Year, dt.Month)
"

and i need to convert this integer "day" to a date

Please Help

Convert Integer To Date?
hi to all,

i have a field name datetime from my SQL/database with a data type integer. i want to convert records to date.

sample records:
1143686990
1143687132
1143687316
1143691271

any idea how to do this?

noielen

Convert Integer To Float
I am trying to convert a pair of integers into a floating point variable (they should translate in a float value). I succesfully converted the pair of integers into a Long and i assumed that I was homefree by using the CDbl function. Unfortunately I am just getting the same number in the Double variable. The Long has a number like 1141187758 and this should translate in something like 530.xxx as a float. Anybody who can help me with this?

How To Convert Byte To Integer?
er... you posted this question a lot... without any details...

is this what you want?


VB Code:
Dim someVar As ByteDim someOther As Integer' assign stuff to byte ' implicitly converts byte to integersomeOther = someVar ' do stuff with integer  


- Dim A

Convert Text Into An Integer
I want to check if the value entered into the text box is an integer and is non negative.

Here is the code tht i have written.
However,it gives me an error at the Cint line.
here is the vbcode

<vbcode>

Private Sub txtWorkHrs_Change()

If IsNumeric(txtWorkHrs.Text) = False Then
MsgBox "Please enter a numeric value"
txtWorkHrs.Text = ""
txtWorkHrs.SetFocus
End If

If txtWorkHrs.Text < 0 Then
MsgBox "Working hrs cannot be negative."
txtWorkHrs.Text = ""
txtWorkHrs.SetFocus
End If
Dim workhrs As Integer

workhrs = CInt(txtWorkHrs.Text)


If workhrs < 6 Or workhrs > 12 Then
MsgBox "Please follow the instructions"
txtWorkHrs.Text = ""
txtWorkHrs.SetFocus
'txtGross.Text = txtWorkHrs.Text * txtRate.Text
End If
End Sub

</vbcode>

Thanks!
Jayashree.

Howto: Convert Hex --&gt; Integer In VB?
say I had a var
dim vHex as string
vHex = "&hhe" 'that's a hex code
vHextoInt = '?? ChangeHextoIntegerFunction ?? (vHex)
and I wanted to stuff it into a byte
dim vByteVar as Byte
vByteVar = Cbyte(vHextoInt)

How do I convert the Hex to Int??

Copyright © 2005-08 www.BigResource.com, All rights reserved