Macro returns #REF! in excel - vba

I don't know if this is the place to ask such a question, but since it was regarding some VBA scripting, I thought it might.
I have been writing this Macro function:
Function Mod10(tl As String) As Byte
Dim c(13) As Integer
Dim er As Integer
c(13) = Mid(tl, 14, 1) * 2
c(12) = Mid(tl, 13, 1)
c(11) = Mid(tl, 12, 1) * 2
c(10) = Mid(tl, 11, 1)
c(9) = Mid(tl, 10, 1) * 2
c(8) = Mid(tl, 9, 1)
c(7) = Mid(tl, 8, 1) * 2
c(6) = Mid(tl, 7, 1)
c(5) = Mid(tl, 6, 1) * 2
c(4) = Mid(tl, 5, 1)
c(3) = Mid(tl, 4, 1) * 2
c(2) = Mid(tl, 3, 1)
c(1) = Mid(tl, 2, 1) * 2
c(0) = Mid(tl, 1, 1)
For i = 0 To 13
If c(i) > 9 Then
c(i) = CInt(Left(c(i), 1)) + CInt(Right(c(i), 1))
End If
Next
er = 0
For i = 0 To 13
er = er + c(i)
Next
Mod10 = 10 - er Mod 10
End Function
But as you can see here in this picture:
it returns an error saying #REF!. i am writing this in the fx: =Mod10(a1).
The script is found here: http://kronsell.net/fikkontrol.htm (a danish site)
It is used to calculate the final digit to a string. A bit like when calculating the EAN-13 code, just another kind of calculation.
If anybody with VBA or EXCEL knowledge could tell me what to do, I'd really appreciate it.

Not sure why, but it looks like Mod10 is a reserved keyword. I tried renaming the function to Mod_10 and it worked.
You may need to declare some variables if you hold Option Explicit at the top of your module.
Try this and call it from a cell with =MOD_10(A1)
Function MOD_10(tl As String) As Byte
Dim i As Long
Dim c(13) As Integer
Dim er As Integer
c(13) = Mid(tl, 14, 1) * 2
c(12) = Mid(tl, 13, 1)
c(11) = Mid(tl, 12, 1) * 2
c(10) = Mid(tl, 11, 1)
c(9) = Mid(tl, 10, 1) * 2
c(8) = Mid(tl, 9, 1)
c(7) = Mid(tl, 8, 1) * 2
c(6) = Mid(tl, 7, 1)
c(5) = Mid(tl, 6, 1) * 2
c(4) = Mid(tl, 5, 1)
c(3) = Mid(tl, 4, 1) * 2
c(2) = Mid(tl, 3, 1)
c(1) = Mid(tl, 2, 1) * 2
c(0) = Mid(tl, 1, 1)
For i = 0 To 13
If c(i) > 9 Then
c(i) = CInt(Left(c(i), 1)) + CInt(Right(c(i), 1))
End If
Next
er = 0
For i = 0 To 13
er = er + c(i)
Next
MOD_10 = 10 - er Mod 10
End Function

Related

Collection of list of integer changing number to access the different variable names

Public p1 = New List(Of Integer)({1, 2, 3, 4, 5, 6, 7, 8, 9, 10})
Public p2 = New List(Of Integer)({5, 4, 6, 7, 3, 8, 9, 10, 2, 11})
Public p3 = New List(Of Integer)({11, 8, 10, 9, 7, 12, 6, 13, 14, 15})
I want to display the list p depending on how much is A. if a is 1 then it will be p1, if a is 2 then it will be p2. how can i access the list using this loop without having to manually write the code so many times.
For a As Integer = 1 To 20
If strDigit(str) = a Then
If a = 1 Then
Dim astr As Integer = 0
For Each num In p1
astr = Val(astr) + 1
If num + 1 >= 1 AndAlso num + 1 <= 1000 Then
If pos < 5 Then
Else
End If
End If
Next
ElseIf a = 2 Then
For Each num In p2
Dim astr As Integer = 0
If num + 1 >= 1 AndAlso num + 1 <= 1000 Then
If pos < 5 Then
Else
End If
End If
Next
ElseIf a = 3 Then
For Each num In p3
Dim astr As Integer = 0
astr = Val(astr) + 1
If num + 1 >= 1 AndAlso num + 1 <= 1000 Then
If pos < 5 Then
Else
End If
Next
This should normally be the case, but it doesn't work that way.
For a As Integer = 1 To 20
If strDigit(str) = a Then
If a = 1 Then ' remove line
Dim astr As Integer = 0
For Each num In p(a) ' here
astr = Val(astr) + 1
If num + 1 >= 1 AndAlso num + 1 <= 1000 Then
If pos < 5 Then
Else
End If
End If
Next
End If
Try this one with sorted list
Dim slist As New SortedList(Of Integer, List(Of Integer))
Dim p1 = New List(Of Integer)({1, 2, 3, 4, 5, 6, 7, 8, 9, 10})
slist.Add(1, p1)
Dim p2 = New List(Of Integer)({5, 4, 6, 7, 3, 8, 9, 10, 2, 11})
slist.Add(2, p2)
Dim p3 = New List(Of Integer)({11, 8, 10, 9, 7, 12, 6, 13, 14, 15})
slist.Add(3, p3)
Dim p4 = New List(Of Integer)({9, 16, 2, 43, 12, 11, 21, 22, 23})
slist.Add(4, p4)
Dim tmpList As List(Of Integer)
For Each a In slist.Keys
If slist.ContainsKey(a) = True Then
tmpList = slist.Item(a)
For Each num In tmpList
astr = Val(astr) + 1
If num + 1 >= 1 AndAlso num + 1 <= 1000 Then
If pos < 5 Then
Else
End If
End If
Next
End If
Next
LINQ is a great way to make code that would normally involve a loop more succinct.
Dim lists = {p1, p2, p3}
Dim list = lists.First(Function(l) l.Contains(A))
If more than one list contains the specified number, that code will return the first one in which it is found, so that would depend on the order you search them.

Change Number of Categories between Tick-Mark Labels on Chart X-axis

If I have more (or less) data in my Access 2010 graph, I want to decrease (or increase) the number of tick marks on the X-axis. I looked for the right syntax but I couldn't find it.
I did the same for the Y-axis Title and that works fine:
me.Graph1.Object.Axes(2,1).AxisTitles.Caption="g/ml"
For number of tick-marks of the X-axis; I've tried a number of words can not find the right one. It stopped at:
me.Graph.Object.Axes(1,1).Scale.???????? (I want a number of categories = 3 )
Example code from my db for XYScatter chart. xlCategory is for X-axis and xlValue is Y-axis.
this procedure is in a standard module and called by a form and a report
Sub FormatProcGraph(strObject As String, strLabNum As String, booMetric As Boolean, dblOMC, dblMDD)
'format Proctor graph on form and report
Dim obj As Object
Dim gc As Object
Dim intMaxD As Integer
Dim intMinD As Integer
Dim intM As Integer
If strObject Like "Lab*" Then
Set obj = Reports(strObject)
Else
Set obj = Forms(strObject).Controls("ctrProctor").Form
End If
Set gc = obj("gphDensity")
intMaxD = Nz(Int(dblMDD), 0)
intMinD = Nz(Int(DMin("D", "GraphProctor", "Source='Lab' AND LabNum='" & strLabNum & "'")), 0)
With gc
'format y axis scale
If booMetric = True Then
intMaxD = intMaxD + IIf(intMaxD - intMinD < 125, 50, IIf(intMaxD - intMinD < 250, 25, 0))
.Axes(xlValue).MaximumScale = intMaxD
.Axes(xlValue).MinimumScale = intMaxD - 250
.Axes(xlValue).MajorUnit = 50
.Axes(xlValue).MinorUnit = 10
Else
intMaxD = intMaxD + IIf(intMaxD - intMinD < 6, 2, IIf(intMaxD - intMinD < 10, 1, 0))
.Axes(xlValue).MaximumScale = intMaxD
.Axes(xlValue).MinimumScale = intMaxD - 10
.Axes(xlValue).MajorUnit = 2
.Axes(xlValue).MinorUnit = 0.4
End If
'format x axis scale
If Int(dblOMC) > 6 Then
intM = Int(dblOMC) + IIf(dblOMC - Int(dblOMC) >= 0.5, 1, 0)
.Axes(xlCategory).MaximumScale = intM + 7
.Axes(xlCategory).MinimumScale = intM - 5
End If
'y axis label
.Axes(xlValue, xlPrimary).HasTitle = True
If booMetric = True Then
.Axes(xlValue, xlPrimary).AxisTitle.Text = "Dry Density, kg/cu.m"
End If
End With
End Sub
this procedure is behind report
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
'format graphs
Dim MinUWT As Double, MaxUWT As Double
Dim MinDry As Double, MaxDry As Double
Dim MinSoak As Double, MaxSoak As Double
Dim MinRat As Double, MaxRat As Double
With Me
If Not IsNull(!MinOfA) Then
MinUWT = Int(!MinOfU) - IIf(!MaxOfU - !MinOfU <= 2, 3, 1)
MaxUWT = MinUWT + 8
MinDry = Int(!MinOfD / 5) * 5 - (40 - Int((Int(!MaxOfD / 5) * 5 + 5 - Int(!MinOfD / 5) * 5) / 10) * 10) / 2
MaxDry = MinDry + 40
MinSoak = Int(!MinOfS / 5) * 5 - (40 - Int((Int(!MaxOfS / 5) * 5 + 5 - Int(!MinOfS / 5) * 5) / 10) * 10) / 2
MaxSoak = MinSoak + 40
MinRat = Int(!MinOfR / 5) * 5 - (40 - Int((Int(!MaxOfR / 5) * 5 + 5 - Int(!MinOfR / 5) * 5) / 10) * 10) / 2
MaxRat = MinRat + 40
.gphWeight.Axes(xlValue).MinimumScale = MinUWT
.gphWeight.Axes(xlValue).MaximumScale = MaxUWT
.gphITSdry.Axes(xlValue).MinimumScale = MinDry
.gphITSdry.Axes(xlValue).MaximumScale = MaxDry
.gphITSsoak.Axes(xlValue).MinimumScale = MinSoak
.gphITSsoak.Axes(xlValue).MaximumScale = MaxSoak
.gphITSret.Axes(xlValue).MinimumScale = MinRat
.gphITSret.Axes(xlValue).MaximumScale = MaxRat
If Me!Metric = True Then
.gphWeight.Axes(xlValue, xlPrimary).AxisTitle.Text = "Unit Weight, kg/cu.cm"
.gphGradation.Axes(xlCategory, xlPrimary).AxisTitle.Text = "Sieve Size (mm)"
.gphITSdry.Axes(xlValue, xlPrimary).AxisTitle.Text = "ITS Dry, kg/cu.cm"
.gphITSsoak.Axes(xlValue, xlPrimary).AxisTitle.Text = "ITS Soaked, kg/cu.cm"
End If
End If
End With
End Sub

How can I write a code where the values are 'stepped'?

I just started programming in Excel VBA and I have a question.
How can I write a code where the values are 'stepped'?
I want to code this by using do until, do while and for only.
I'm using two variables: x = 1 and y = 1. The value must be the number of the cycle.
The output would look like this:
cells(x,y). value = a
cells(2x,y). value = 2a
cells(2x,2y). value = 3a
cells(3x,2y). value = 4a
cells(3x,3y). value = 5a
cells(4x,3y). value = 6a
cells(4x,4y). value = 7a
This would be an alternative version to do it
Option Explicit
Public Sub Generate()
Dim a As Long: a = 1
Dim i As Long
For i = 1 To 7
Cells((i \ 2) + 1, ((i - 1) \ 2) + 1).Value = i * a
Next i
End Sub
Note that this uses the div Operator 5 \ 2 which is not a standard division 5 / 2. The div operator divides two numbers and returns an integer result.
Standard division of 5 / 2 = 2.5
Div Operator of 5 / 2 = 2
So (i \ 2) + 1, ((i - 1) \ 2) + 1 results in
1, 1
2, 1
2, 2
3, 2
3, 3
4, 3
4, 4
You can step through your sequence in VBA using arrays like so:
Sub StepAXY()
Dim Z As Long, A As Long, X As Long, Y As Long
Dim arrA() As Variant, arrX() As Variant, arrY() As Variant
arrA = Array(1, 2, 3, 4, 5, 6, 7)
arrX = Array(1, 2, 2, 3, 3, 4, 4)
arrY = Array(1, 1, 2, 2, 3, 3, 4)
For Z = 1 To 7 Step 1
A = arrA(Z - 1)
X = arrX(Z - 1)
Y = arrY(Z - 1)
Cells(X * 1, Y * 1) = A * 1
Next Z
End Sub
Here is a different approach. This will give you an extra row (5x,4y) so if this is not desired can be excluded using an If statement.
Sub Generate()
Dim x As Long, y As Long, a As Long, b As Long, c As Long
For b = 1 To 4
Cells(b * x, b * y) = (2 * b - 1) * a
Cells((b + 1) * x, b * y) = 2 * b * a
Next b
End Sub

Securely store password in a VBA project

I built a file used by various people in one of my company service.
Each sheet is protected by a password and all users entries are handled with a VBA user form. All sheets are protected by the same password and my code protect/unprotect sheet when users modify data.
The problem is I'm storing the password in clear text in the VBA project so as to call the ActiveSheet.Protect password method. The VBA project is also protected by this password.
Is there a secure way to store that password in the VBA project ?
Anyone who knows how to search a bit would find a code to crack that VBA project password and be able to read it.
EDIT :
I have thought of computing a new password each time the file is open by adding some randomness in it. This way one could read the code without knowing the password. Adding a msgbox could reveal it but only until the file is reopenend. The problem is I cannot manually unprotect/protect sheet with that method as I won't be aware of the password.
Summarising the useful info from comments:
if your code has access to the password (even directly or through obfuscation) anybody having access to the code have access to the password too
password protection of Excel VBA is very weak, it's a trivial job to crack it
Conclusion : there is no way securely storing password in Excel VBA
This should do the trick. The password is smp2smp2, which you will get when running GetPassword, but that actual value is not stored in the project. It is stored using the code 30555112012321187051111661144119, which will be converted to the actual password (human readable) by using CreatePasswordFromCode. By the way, I have no idea how to easily get the code that belongs to a certain password. And in this way, it is always 8 characters long, no room for changes unless you adjust the code. I have found this somewhere in an old project of somebody else, no source mentioned unfortunately.
Option Explicit
Function GetPassword() As String
'the password is stored as codes, so the real password is not stored in this project
GetPassword = CreatePasswordFromCode("30555112012321187051111661144119")
End Function
Function CreatePasswordFromCode(ByVal pstrPasswordCode As String) As String
Dim intChar As Integer
Dim intCode As Integer
Dim arrintShifts(0 To 7) As Integer
Dim arrlngCharCode(0 To 7) As Long
Dim strMessage As String
intChar = 0
intCode = 0
For intCode = 0 To 7
'store -8 to -1 into 0-7
arrintShifts(intCode) = intCode - 8
Next intCode
'the code is stored by using the number of the letter of the password in the 4th character.
'the real code of the character is directly behind that.
'so the code 30555112012321187051111661144119
'has on position 3, 055, 5, 112, 0, 123, 2, 118, 7, 051, 1, 116, 6, 114 and 4, 119
'so sorted this is 0, 123, 1, 116, 2, 118, 3, 055, 4, 119, 5, 112, 6, 114, 7, 051
'then there is also the part where those charcode are shifted by adding -8 to -1 to them.
'leading to the real charactercodes:
'0, 123-8, 1, 116-7, 2, 118-6, 3, 055-5, 4, 119-4, 5, 112-3, 6, 114-2, 7, 051-1
'0, 115, 1, 109, 2, 112, 3, 050, 4, 115, 5, 109, 6, 112, 7, 050
For intChar = 0 To 7
If Mid(pstrPasswordCode, 1, 1) = intChar Then
arrlngCharCode(intChar) = (Mid(pstrPasswordCode, 2, 3) + arrintShifts(intChar))
ElseIf Mid(pstrPasswordCode, 5, 1) = intChar Then
arrlngCharCode(intChar) = (Mid(pstrPasswordCode, 6, 3) + arrintShifts(intChar))
ElseIf Mid(pstrPasswordCode, 9, 1) = intChar Then
arrlngCharCode(intChar) = (Mid(pstrPasswordCode, 10, 3) + arrintShifts(intChar))
ElseIf Mid(pstrPasswordCode, 13, 1) = intChar Then
arrlngCharCode(intChar) = (Mid(pstrPasswordCode, 14, 3) + arrintShifts(intChar))
ElseIf Mid(pstrPasswordCode, 17, 1) = intChar Then
arrlngCharCode(intChar) = (Mid(pstrPasswordCode, 18, 3) + arrintShifts(intChar))
ElseIf Mid(pstrPasswordCode, 21, 1) = intChar Then
arrlngCharCode(intChar) = (Mid(pstrPasswordCode, 22, 3) + arrintShifts(intChar))
ElseIf Mid(pstrPasswordCode, 25, 1) = intChar Then
arrlngCharCode(intChar) = (Mid(pstrPasswordCode, 26, 3) + arrintShifts(intChar))
ElseIf Mid(pstrPasswordCode, 29, 1) = intChar Then
arrlngCharCode(intChar) = (Mid(pstrPasswordCode, 30, 3) + arrintShifts(intChar))
End If
Next intChar
'by getting the charcodes of these values, you create the password
CreatePasswordFromCode = Chr(arrlngCharCode(0)) & Chr(arrlngCharCode(1)) & Chr(arrlngCharCode(2)) & Chr(arrlngCharCode(3)) & Chr(arrlngCharCode(4)) & Chr(arrlngCharCode(5)) & Chr(arrlngCharCode(6)) & Chr(arrlngCharCode(7))
End Function
Modified the code for use with up to 99 characters. Added Password generator.
But still: this all is just an obfuscation of the real password.
Function CreatePasswordFromCode(ByVal pstrPasswordCode As String) As String
' Original Code https://stackoverflow.com/questions/47990187/securely-store-password-in-a-vba-project?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa
' Modified to extend password length
' Modifications free to use
Dim codeLen As Integer
Dim intChar As Integer
Dim intCode As Integer
Dim arrintShifts() As Integer
Dim arrlngCharCode() As Long
Dim icp As Integer
' Initialise Arrays
icp = IIf(Right(pstrPasswordCode, 1) Mod 2 = 0, 5, 4)
pstrPasswordCode = Left(pstrPasswordCode, Len(pstrPasswordCode) - IIf(Right(pstrPasswordCode, 1) Mod 2 = 0, 1, 1))
codeLen = Len(pstrPasswordCode) / icp - 1 ' Array Index starts with 0
ReDim arrintShifts(codeLen)
ReDim arrlngCharCode(codeLen)
intChar = 0
intCode = 0
For intCode = 0 To codeLen
'store -8 to -1 into 0-7
arrintShifts(intCode) = intCode - (codeLen + 1)
Next intCode
'the code is stored by using the number of the letter of the password in the 4th character.
'the real code of the character is directly behind that.
'so the code 30555112012321187051111661144119
'has on position 3, 055, 5, 112, 0, 123, 2, 118, 7, 051, 1, 116, 6, 114 and 4, 119
'so sorted this is 0, 123, 1, 116, 2, 118, 3, 055, 4, 119, 5, 112, 6, 114, 7, 051
'then there is also the part where those charcode are shifted by adding -8 to -1 to them.
'leading to the real charactercodes:
'0, 123-8, 1, 116-7, 2, 118-6, 3, 055-5, 4, 119-4, 5, 112-3, 6, 114-2, 7, 051-1
'0, 115, 1, 109, 2, 112, 3, 050, 4, 115, 5, 109, 6, 112, 7, 050
For intChar = 0 To codeLen
For intCode = 0 To codeLen
If CInt(Mid(pstrPasswordCode, intCode * icp + 1, icp - 3)) = intChar Then
arrlngCharCode(intChar) = (Mid(pstrPasswordCode, (intCode + 1) * icp - 2, 3) + arrintShifts(intChar))
Exit For
End If
Next intCode
Next intChar
'by getting the charcodes of these values, you create the password
CreatePasswordFromCode = ""
For intChar = 0 To codeLen
CreatePasswordFromCode = CreatePasswordFromCode & Chr(arrlngCharCode(intChar))
Next intChar
End Function
Function CreateCodeFromPassword(ByVal pstrPasswordCode As String) As String
' Generator free to use
Dim pwLen As Integer
Dim scp As String ' String Code Position, for formatting "0" or "00"
Dim icp As Integer ' marker if pwLen < 10 or > 10
Dim intCode As Integer
Dim arrintShifts() As Integer
Dim arrlngCharCode() As Long
Dim pw() As String
Dim Temp As Variant
Dim arnd() As Variant
Dim irnd As Variant
Randomize
' Initialise Arrays
pwLen = Len(pstrPasswordCode) - 1 ' Array Index starts with 0
scp = IIf(pwLen < 10, "0", "00")
' Create odd/even marker if we have 1 (odd) or 2 (even) byte index digits (scp), values between 0 and 9
icp = IIf(pwLen < 10, Int(Rnd() * 5 + 1) * 2 - 1, Int(Rnd() * 5 + 1) * 2)
ReDim arrintShifts(pwLen)
ReDim arrlngCharCode(pwLen)
ReDim pw(pwLen)
ReDim arnd(pwLen)
For intCode = 0 To pwLen
arnd(intCode) = intCode
Next intCode
' randomize the indizes to bring the code into a random order
For intCode = LBound(arnd) To UBound(arnd)
irnd = CLng(((UBound(arnd) - intCode) * Rnd) + intCode)
If intCode <> irnd Then
Temp = arnd(intCode)
arnd(intCode) = arnd(irnd)
arnd(irnd) = Temp
End If
Next intCode
'by getting the charcodes of these values, you create the password
For intCode = 0 To pwLen
'get characters
pw(intCode) = Mid(pstrPasswordCode, intCode + 1, 1)
'and store -8 to -1 into 0-7 (for additional obfuscation)
arrintShifts(intCode) = intCode - (pwLen + 1)
Next intCode
' Search for the random index and throw the shifted code at this position
For intCode = 0 To pwLen
arrlngCharCode(Application.Match(intCode, arnd, False) - 1) = AscB(pw(intCode)) - arrintShifts(intCode)
Next intCode
' Chain All Codes, combination of arnd(intcode) and arrlngCharCode(intcode) gives the random order
CreateCodeFromPassword = ""
For intCode = 0 To pwLen
CreateCodeFromPassword = CreateCodeFromPassword & Format(arnd(intCode), scp) & Format(arrlngCharCode(intCode), "000")
Next intCode
CreateCodeFromPassword = CreateCodeFromPassword & icp
End Function
Obfuscated version
'VBA code protection using: www.excel-pratique.com/en/vba_tricks/vba-obfuscator.php
Function CreatePasswordFromCode(ByVal z4891679d877f1da36647b21d6197fbfd As String) As String
Dim b2da54ddb60c93bf346493d7e08bc6d08 As Integer
Dim bf56f94eb6ed9a658e82e88591237324d As Integer
Dim bec732ae8e18b7b2ff2e9ccd058f3e8fc As Integer
Dim m06993036154505accc9ce092bdb57b17() As Integer
Dim b8026f9f8f7fe86372be0799d8c9c6691() As Long
Dim q24471047c7a6e466b78de3c6ae66f20f As String
Dim t5f443e88a552a3f943275f985dde03ca As Integer
t5f443e88a552a3f943275f985dde03ca = IIf(Right(z4891679d877f1da36647b21d6197fbfd, 1) Mod 2 = 0, 5, 4)
z4891679d877f1da36647b21d6197fbfd = Left(z4891679d877f1da36647b21d6197fbfd, Len(z4891679d877f1da36647b21d6197fbfd) - IIf(Right(z4891679d877f1da36647b21d6197fbfd, 1) Mod 2 = 0, 1, 1))
b2da54ddb60c93bf346493d7e08bc6d08 = Len(z4891679d877f1da36647b21d6197fbfd) / t5f443e88a552a3f943275f985dde03ca - 1
ReDim m06993036154505accc9ce092bdb57b17(b2da54ddb60c93bf346493d7e08bc6d08)
ReDim b8026f9f8f7fe86372be0799d8c9c6691(b2da54ddb60c93bf346493d7e08bc6d08)
bf56f94eb6ed9a658e82e88591237324d = 0
bec732ae8e18b7b2ff2e9ccd058f3e8fc = 0
For bec732ae8e18b7b2ff2e9ccd058f3e8fc = 0 To b2da54ddb60c93bf346493d7e08bc6d08
m06993036154505accc9ce092bdb57b17(bec732ae8e18b7b2ff2e9ccd058f3e8fc) = bec732ae8e18b7b2ff2e9ccd058f3e8fc - (b2da54ddb60c93bf346493d7e08bc6d08 + 1)
Next bec732ae8e18b7b2ff2e9ccd058f3e8fc
For bf56f94eb6ed9a658e82e88591237324d = 0 To b2da54ddb60c93bf346493d7e08bc6d08
For bec732ae8e18b7b2ff2e9ccd058f3e8fc = 0 To b2da54ddb60c93bf346493d7e08bc6d08
If CInt(Mid(z4891679d877f1da36647b21d6197fbfd, bec732ae8e18b7b2ff2e9ccd058f3e8fc * t5f443e88a552a3f943275f985dde03ca + 1, t5f443e88a552a3f943275f985dde03ca - 3)) = bf56f94eb6ed9a658e82e88591237324d Then
b8026f9f8f7fe86372be0799d8c9c6691(bf56f94eb6ed9a658e82e88591237324d) = (Mid(z4891679d877f1da36647b21d6197fbfd, (bec732ae8e18b7b2ff2e9ccd058f3e8fc + 1) * t5f443e88a552a3f943275f985dde03ca - 2, 3) + m06993036154505accc9ce092bdb57b17(bf56f94eb6ed9a658e82e88591237324d))
Exit For
End If
Next bec732ae8e18b7b2ff2e9ccd058f3e8fc
Next bf56f94eb6ed9a658e82e88591237324d
CreatePasswordFromCode = ""
For bf56f94eb6ed9a658e82e88591237324d = 0 To b2da54ddb60c93bf346493d7e08bc6d08
CreatePasswordFromCode = CreatePasswordFromCode & Chr(b8026f9f8f7fe86372be0799d8c9c6691(bf56f94eb6ed9a658e82e88591237324d))
Next bf56f94eb6ed9a658e82e88591237324d
End Function
Function CreateCodeFromPassword(ByVal z4891679d877f1da36647b21d6197fbfd As String) As String
Dim qe564274d6cab7b91a3393ef092dac78f As Integer
Dim b330c8da5472f3c36b801671ef5a54797 As String
Dim t5f443e88a552a3f943275f985dde03ca As Integer
Dim bec732ae8e18b7b2ff2e9ccd058f3e8fc As Integer
Dim m06993036154505accc9ce092bdb57b17() As Integer
Dim b8026f9f8f7fe86372be0799d8c9c6691() As Long
Dim b343223dcae485b35af2792c7dd91f92b() As String
Dim e0d4cf763c9da42470a729a29b30d7d50 As Variant
Dim b41d8f2e79c0e09113beb7629aa0d8c48() As Variant
Dim b42a57d0c121b9fe34a74143aa279157c As Variant
Randomize
qe564274d6cab7b91a3393ef092dac78f = Len(z4891679d877f1da36647b21d6197fbfd) - 1
b330c8da5472f3c36b801671ef5a54797 = IIf(qe564274d6cab7b91a3393ef092dac78f < 10, "0", "00")
t5f443e88a552a3f943275f985dde03ca = IIf(qe564274d6cab7b91a3393ef092dac78f < 10, Int(Rnd() * 5 + 1) * 2 - 1, Int(Rnd() * 5 + 1) * 2)
ReDim m06993036154505accc9ce092bdb57b17(qe564274d6cab7b91a3393ef092dac78f)
ReDim b8026f9f8f7fe86372be0799d8c9c6691(qe564274d6cab7b91a3393ef092dac78f)
ReDim b343223dcae485b35af2792c7dd91f92b(qe564274d6cab7b91a3393ef092dac78f)
ReDim b41d8f2e79c0e09113beb7629aa0d8c48(qe564274d6cab7b91a3393ef092dac78f)
For bec732ae8e18b7b2ff2e9ccd058f3e8fc = 0 To qe564274d6cab7b91a3393ef092dac78f
b41d8f2e79c0e09113beb7629aa0d8c48(bec732ae8e18b7b2ff2e9ccd058f3e8fc) = bec732ae8e18b7b2ff2e9ccd058f3e8fc
Next bec732ae8e18b7b2ff2e9ccd058f3e8fc
For bec732ae8e18b7b2ff2e9ccd058f3e8fc = LBound(b41d8f2e79c0e09113beb7629aa0d8c48) To UBound(b41d8f2e79c0e09113beb7629aa0d8c48)
b42a57d0c121b9fe34a74143aa279157c = CLng(((UBound(b41d8f2e79c0e09113beb7629aa0d8c48) - bec732ae8e18b7b2ff2e9ccd058f3e8fc) * Rnd) + bec732ae8e18b7b2ff2e9ccd058f3e8fc)
If bec732ae8e18b7b2ff2e9ccd058f3e8fc <> b42a57d0c121b9fe34a74143aa279157c Then
e0d4cf763c9da42470a729a29b30d7d50 = b41d8f2e79c0e09113beb7629aa0d8c48(bec732ae8e18b7b2ff2e9ccd058f3e8fc)
b41d8f2e79c0e09113beb7629aa0d8c48(bec732ae8e18b7b2ff2e9ccd058f3e8fc) = b41d8f2e79c0e09113beb7629aa0d8c48(b42a57d0c121b9fe34a74143aa279157c)
b41d8f2e79c0e09113beb7629aa0d8c48(b42a57d0c121b9fe34a74143aa279157c) = e0d4cf763c9da42470a729a29b30d7d50
End If
Next bec732ae8e18b7b2ff2e9ccd058f3e8fc
For bec732ae8e18b7b2ff2e9ccd058f3e8fc = 0 To qe564274d6cab7b91a3393ef092dac78f
b343223dcae485b35af2792c7dd91f92b(bec732ae8e18b7b2ff2e9ccd058f3e8fc) = Mid(z4891679d877f1da36647b21d6197fbfd, bec732ae8e18b7b2ff2e9ccd058f3e8fc + 1, 1)
m06993036154505accc9ce092bdb57b17(bec732ae8e18b7b2ff2e9ccd058f3e8fc) = bec732ae8e18b7b2ff2e9ccd058f3e8fc - (qe564274d6cab7b91a3393ef092dac78f + 1)
Next bec732ae8e18b7b2ff2e9ccd058f3e8fc
For bec732ae8e18b7b2ff2e9ccd058f3e8fc = 0 To qe564274d6cab7b91a3393ef092dac78f
b8026f9f8f7fe86372be0799d8c9c6691(Application.Match(bec732ae8e18b7b2ff2e9ccd058f3e8fc, b41d8f2e79c0e09113beb7629aa0d8c48, False) - 1) = AscB(b343223dcae485b35af2792c7dd91f92b(bec732ae8e18b7b2ff2e9ccd058f3e8fc)) - m06993036154505accc9ce092bdb57b17(bec732ae8e18b7b2ff2e9ccd058f3e8fc)
Next bec732ae8e18b7b2ff2e9ccd058f3e8fc
CreateCodeFromPassword = ""
For bec732ae8e18b7b2ff2e9ccd058f3e8fc = 0 To qe564274d6cab7b91a3393ef092dac78f
CreateCodeFromPassword = CreateCodeFromPassword & Format(b41d8f2e79c0e09113beb7629aa0d8c48(bec732ae8e18b7b2ff2e9ccd058f3e8fc), b330c8da5472f3c36b801671ef5a54797) & Format(b8026f9f8f7fe86372be0799d8c9c6691(bec732ae8e18b7b2ff2e9ccd058f3e8fc), "000")
Next bec732ae8e18b7b2ff2e9ccd058f3e8fc
CreateCodeFromPassword = CreateCodeFromPassword & t5f443e88a552a3f943275f985dde03ca
End Function

vb.net multi dimensional arrays

net right now regarding multi dimensional array my problem is i want to get the nearest numbers for example my input was 13000, the nearest number will be 11667 and then it will subtract it by 13000, then it will multiply by 0.25 and add my 1875.00. here is my code about multidimensional array can you please help me regarding this? i need this in my project thank you in advance
If ComboBox5.Text = "Z" Then
Dim zero(3, 8) As Double
Dim row As Double
Dim col As Double
'col 1
zero(0, 0) = 0.0
zero(1, 0) = 0
zero(2, 0) = 1
'col 2
zero(0, 1) = 0.0
zero(1, 1) = 0.05
zero(2, 1) = 0
'col 3
zero(0, 2) = 41.67
zero(1, 2) = 0.1
zero(2, 2) = 833
'col 4
zero(0, 3) = 208.33
zero(1, 3) = 0.15
zero(2, 3) = 2500
'col 5
zero(0, 4) = 708.33
zero(1, 4) = 0.2
zero(2, 4) = 5833
'col 6
zero(0, 5) = 1875.0
zero(1, 5) = 0.25
zero(2, 5) = 11667
'col 7
zero(0, 6) = 4166.67
zero(1, 6) = 0.3
zero(2, 6) = 20833
'col 8
zero(0, 7) = 10416.67
zero(1, 7) = 0.32
zero(2, 7) = 41667
For row = 0 To 3
For col = 0 To 8
If Val(TextBox18.Text) > Val(zero(row, col)) And Val(TextBox18.Text) < Val(zero(row - 1, col + 1)) Then
ListView1.Items.Add(zero(row, col))
End If
Next
Next
End If
2D array is not very appropriate to store this kind of data, but here is an example to get you started:
Dim data(,) = {
{0.0, 0, 1},
{0.0, 0.05, 0},
{41.67, 0.1, 833},
{208.33, 0.15, 2500},
{708.33, 0.2, 5833},
{1875.0, 0.25, 11667},
{4166.67, 0.3, 20833},
{10416.67, 0.32, 41667}}
Dim value = 13000 ' Dim value = Val(TextBox18.Text)
' data.GetLength(0) is 8, so Enumerable.Range generates the numbers from 0 to 7
Dim range = Enumerable.Range(0, data.GetLength(0))
' .OrderBy orders them by the difference between value and the last column in data
Dim ordered = range.OrderBy(Function(i) Math.Abs(data(i, 2) - value)) ' 5,4,6,3,2,0,1,7
Dim nearestIndex = ordered.First ' 5
Dim value1 = data(nearestIndex, 0) ' 1875.0
Dim value2 = data(nearestIndex, 1) ' 0.25
Dim value3 = data(nearestIndex, 2) ' 11667
Dim result = (value3 - value) * value2 + value1 ' result = 1541.75