Hi, this is my first thread so be kind!!
I've made a very brute force algorithm in vb.net to decompose a number and achive the following.
1. I can have any number from 0 to 999999, the leght of this number is fixed at 6 figures.
2. In order to send this number, or any within, there are two registers that have a value of multiples of 50 and 1. (for example if I want to send number 41, then I would have to send registerA that has a value of 1, 41 times since 41 it's not multiple of 50, instead if I were to send number 51, then I would send one registerB, wich has a value of 50, and one registerA, wich has a value of 1)
So, I have two available numbers (50 or 1) to complete any number from 1 to 999999.
this is the code that i've implemented in VB.NET this is actually working flawlessly, but my guts says that there has to be a better way, I know that it may be a pain to go trough to, but this is really itching me.
please feel free to ask, don't be shy now...
here we go
I've made a very brute force algorithm in vb.net to decompose a number and achive the following.
1. I can have any number from 0 to 999999, the leght of this number is fixed at 6 figures.
2. In order to send this number, or any within, there are two registers that have a value of multiples of 50 and 1. (for example if I want to send number 41, then I would have to send registerA that has a value of 1, 41 times since 41 it's not multiple of 50, instead if I were to send number 51, then I would send one registerB, wich has a value of 50, and one registerA, wich has a value of 1)
So, I have two available numbers (50 or 1) to complete any number from 1 to 999999.
this is the code that i've implemented in VB.NET this is actually working flawlessly, but my guts says that there has to be a better way, I know that it may be a pain to go trough to, but this is really itching me.
please feel free to ask, don't be shy now...
here we go
Rich (BB code):
Public Sub transfiere_creditos()
Dim uni, dec, cen, udm, ddm, cdm, xes, nes, lon As Integer
Dim opa As Double
lon = lbl_creditos.Text.Length()
uni = lbl_creditos.Text.Substring(lon - 1, 1)
lon = lon - 1
If lon > 0 Then
dec = lbl_creditos.Text.Substring(lon - 1, 1)
lon = lon - 1
If lon > 0 Then
cen = lbl_creditos.Text.Substring(lon - 1, 1)
lon = lon - 1
If lon > 0 Then
udm = lbl_creditos.Text.Substring(lon - 1, 1)
lon = lon - 1
If lon > 0 Then
ddm = lbl_creditos.Text.Substring(lon - 1, 1)
lon = lon - 1
If lon > 0 Then
cdm = lbl_creditos.Text.Substring(lon - 1, 1)
lon = lon - 1
End If
End If
End If
End If
End If
'decode xes
xes = uni
'decode nes
If dec > 0 Then
opa = dec * 10
opa = opa / 50
End If
If opa < 1 Then
opa = dec * 10
xes = xes + opa
opa = 0
End If
If opa = 1 Then
nes = 1
End If
If opa > 1 Then
nes = 1
opa = dec * 10
opa = opa - 50
xes = xes + opa
End If
'decode centenas
If IsNumeric(cen) = True Then
If cen > 0 Then
opa = cen * 100
opa = opa / 50
nes = nes + opa
End If
End If
'decode udm
If IsNumeric(udm) = True Then
If udm > 0 Then
opa = udm * 1000
opa = opa / 50
nes = nes + opa
End If
End If
'decode ddm
If IsNumeric(ddm) = True Then
If ddm > 0 Then
opa = ddm * 10000
opa = opa / 50
nes = nes + opa
End If
End If
'decode cdm
If IsNumeric(cdm) = True Then
If cdm > 0 Then
opa = cdm * 100000
opa = opa / 50
nes = nes + opa
End If
End If
'Label5.Text = xes
'Label6.Text = nes
lbl_creditos.Text = "0"
Do Until xes = 0
SendKeys.SendWait("x")
xes = xes - 1
Loop
Do Until nes = 0
SendKeys.SendWait("n")
nes = nes - 1
Loop
End Sub