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




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?




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
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!

Help To Convert Byte Array To Ieee Float And Long Integer
Hi,

I'm reading bytes from a binary file in blocks of four bytes.
I now need to convert to ieee float and long integer

I have tried defining a variable as single concatenating bytes and converting by loading to a variable defined as a single,
I have also tried using Csng. I'm obviously missing a step
Here are the two blocks of bytes.
236, 81, 248, 64
205, 204, 0, 65

The results should be 7.76 and 8.05 for the float conversions
but how do I get there.

Thanks
Valter

Converting 16 Bit Integer To 32 Bit Float
I am using a third party OCX that only supports native 16 bits. I am talking to a device through the com port that stores data as a 32 bit floating point value. I can only poll each 16 bit number one at a time, but that returns 65535 for each 16 bit register. I have been told to try using the copymemory() API call, but I am unsure on how I can get the floating point values from this. My function prototype is below:


Modbus.ReadResults(hwnd As Long,slave As Long,register As Long,RetValue As Long)

hwnd is a handler
slave is a device address
register is the physical address of the device (not computer)
RetValue is the value returned.

In order to read two successive registers, I call this .ReadResults Function twice.

Thanks for your assitance

Function To Get Integer Part Of A Float Number
is there any internal function to get the integer part of a float number?

the operator "" , or the cint() function returns round up numbers.

thanks

Convert HEX To Float?
How would I convert a 4-byte HEX value into floating point?

And the inverse; how would I go about converting floating point to 4-byte HEX?

Convert To Float
I was Wonder How To COnvert a 4 byte Hex Decimal to a Floating Char Any help would be aprechated. thanks in advance.

Convert Float To Hex
How to convert float to hex .
Like this 44.549999 to 33333242 (h)
i am using editbox to write a float value to a file

Float FAR* Convert In VB
i have create a ActiveX in VC++ and one of the Method has a parameter "float FAR* MyParameter".
When i want to use this activeX in VB, what shall i put for this paramter? From the object broswe, VB say this is a "MyParameter as single", but i still can't get it work. Any idea? TQ

Sooner Or Later, Everyone Does...

Convert Float To String...
i'll use this code:


Code:
ActiveDocument.Tables(3).Cell((rijindex + 1), 3).Range.Text = CStr(transport)
But i'll get a Integer format

Need a float / double value:

32123,23

Is it possible to format it ? or an other function in stead of CStr ?

Convert Byte To Float In VB
At my VB end i will need to convert every 4 bytes to a floating point number....how do i do this?

Matt

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.

Convert To Float From Byte Values
I have an array of bytes that is a receive buffer from a winsock. Four of these bytes make up a 4 byte float, a single precision number in VB6.

How do I convert these four bytes into a single precision float in VB?

Convert .text Property To A Float
How do i make sure that a text box can only accept a float as an input and how do i read the contents as a float.

For example, to read the contents as an integer you would use the int statment:

int(txtBox.text)

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.

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

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 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 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 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 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 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 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.

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

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??

Convert Constant To Integer
How can I convert for example:
1234567890E+.1234567890
to it's actual number
12345678901234567890
or whatever it'ld be?
(Don't have a calculater big enough to do that question =P)
Thanks,

------------------
DiGiTaIErRoR
VB, QBasic, Iptscrae, HTML
Quote: There are no stupid questions, just stupid people.

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

Need To Convert Integer To Binary And Display It
ok here's the problem.. Let's say I have a number 7.. There is 6 circles in the form and i need to light up the 3 circles because binary equivalent of 7 is 000111.. Another example would be the number 8 which is 001000 in binary therefore i have to light up the 4th circle.. If that's not enough another example would be the number 12, its binary would be 001100, i have to light up the 3rd and 4th circle.. i have no problem lighting them up, the problem is how how to convert. any ideas?... thanks a lot..

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.

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