Divide string by a number

jasn_78

Registered User.
Local time
Today, 18:41
Joined
Aug 1, 2001
Messages
214
hey guys i am trying to convert 2 different strings to integers then divide by each other to return another value (this is just a test at the moment for my rego details) but i keep getting a data mismatch error on the following code. I also should mention the hardwareid contains alpha as well as numeric so i want to be able to convert the whole field to a numeric value.

Me.txtREGO = CDbl(Me.txtHARDWAREID) / CDbl(Me.txtSERIAL)

any help would be appreciated
ps this error also happens with Cint
 
Last edited:
hey guys i am trying to convert 2 different strings to integers then divide by each other to return another value (this is just a test at the moment for my rego details) but i keep getting a data mismatch error on the following code. I also should mention the hardwareid contains alpha as well as numeric so i want to be able to convert the whole field to a numeric value.

Me.txtREGO = CDbl(Me.txtHARDWAREID) / CDbl(Me.txtSERIAL)

any help would be appreciated
ps this error also happens with Cint
I seriously doubt you would get the correct number (if it does work) when using CInt() on an alpha-numeric value. I don't think what you're trying to do is possible, if you want the truth of the matter...

You certainly can't perform the operation as you have it listed now, BUT...you can do it if you want to extract the numerics out of the HARDWAREid first. If you don't want to do that, why not? How can you get any useful data out of dividing a mixed-type string by an actual numeric?? Just wondering. That seems a bit odd in its own right...
 
aje what i am trying to do is use the hard drive id which is the aplha numeric string "HardwareID" to be used in conjunction with the serial number "Numeric" through a calculation which atm is just a divide by to give a rego code now the next step will be to make it a slighty more difficult calculation but i didnt want to waste time doing that till i know i can get the first part to work.


as for extracting the numeric value from the field i am fine with doing that just dont know how as i thought the string format "aaa123aaa" would have to be the same for all records and i doubt that will be the case for hard drive serial numbers.

for example the hardware id on mine is SB3404SRHU9RGE

So if the format doesnt have to be the same on all fields i would be happy with doing that as well.
Thanks
 
for example the hardware id on mine is SB3404SRHU9RGE

So if the format doesnt have to be the same on all fields i would be happy with doing that as well.
Thanks
OK, I don't really get it though. Why in the world would you want to extract the number out of that stuff?

Give me an example...if you want to extract all of the numerics out of that above SN, in what order would you want them to appear, in order to include it in a division process?? I'm hoping the extraction will result in the same order that the numerics appear in the initial SN. Is that what you're looking for here?? If so, that's easy as pie... :)
 
yeah mate thats fine if i can do that i will then play around with randomising it after that.


thank you
 
Extract it in order, like this (x is the result (as integer)):
Code:
Dim x As Integer, i As Integer

  For i = 1 To Len(strINPUT)
    If IsNumeric(Mid(strINPUT, i, 1)) Then
      x = x & Mid(strINPUT, i, 1)
    End If
  Next i
 
Last edited:
adam thanks for ur help with this the only thing in that code i dont understand is the me.text15 field is that meant to be the text field i want to put the new value to or something else?

Thanks Mate
 
adam thanks for ur help with this the only thing in that code i dont understand is the me.text15 field is that meant to be the text field i want to put the new value to or something else?

Thanks Mate

Yeah, sorry about that!! :p I tested the code with a textbox. I changed it now...oops!! Long day... :rolleyes: (strINPUT is your value, wherever it comes from)
 
No probs mate
Dim x As Integer
Dim i As Integer

For i = 1 To Len(Me.txtHARDWAREID)
If IsNumeric(Mid(Me.txtHARDWAREID, i, 1)) Then
x = x & Mid(Me.txtHARDWAREID, i, 1)
End If
Next i

Me.txtREGO = CInt(x) / CInt(Me.txtSERIAL)

i get an overflow error
 
No probs mate
Dim x As Integer
Dim i As Integer

For i = 1 To Len(Me.txtHARDWAREID)
If IsNumeric(Mid(Me.txtHARDWAREID, i, 1)) Then
x = x & Mid(Me.txtHARDWAREID, i, 1)
End If
Next i

Me.txtREGO = CInt(x) / CInt(Me.txtSERIAL)

i get an overflow error
See what this does:
Code:
Me.txtREGO = x / CInt(Me.txtSERIAL)
Also, what data type is txtSERIAL before using the Conv. function on it?

Also, the extracted numeric string from the SN might overflow the integer data type. If that's the case, change x to a DOUBLE.
 
your a great person adam changing it to a double worked a treat thanks for your help on all this greatly appreciated.
 

Users who are viewing this thread

Back
Top Bottom