I have once seen a beautifully and easy to follow enum.
It was written in such a way that one didn't have to calculate the powers by himself (1, 2, 4, 8, 16, 32, 64, 128, etc.), but instead, one could simply write like 1, 2, 3, 4, 5, etc.
The following is surely not correct, but you can get the flavor:
Public Enum eSomething
NotDefined = 0 ^ 2
Max = 1 ^ 2
Jeff = 2 ^ 2
Lisa = 3 ^ 2
Donald = 4 ^ 2
etc...
Does anybody know how to write it correctly?
Thank you very much!
Does this work for you?
Public Enum eSomething
NotDefined = CInt(2 ^ 0)
Max = CInt(2 ^ 1)
Jeff = CInt(2 ^ 2)
Lisa = CInt(2 ^ 3)
Donald = CInt(2 ^ 4)
End Enum
I have this enum that I find a convenient starting place...
<Flags()> Public Enum Bits As Long
none = 0
B00 = 1L << 0 ' 1
B01 = 1L << 1 ' 2
B02 = 1L << 2 ' 4
B03 = 1L << 3 ' 8
B04 = 1L << 4 ' 16
B05 = 1L << 5 ' 32
B06 = 1L << 6 ' 64
B07 = 1L << 7 ' 128
B08 = 1L << 8 ' 256
B09 = 1L << 9 ' 512
B10 = 1L << 10 ' 1,024
B11 = 1L << 11 ' 2,048
B12 = 1L << 12 ' 4,096
B13 = 1L << 13 ' 8,192
B14 = 1L << 14 ' 16,384
B15 = 1L << 15 ' 32,768
B16 = 1L << 16 ' 65,536
B17 = 1L << 17 ' 131,072
B18 = 1L << 18 ' 262,144
B19 = 1L << 19 ' 524,288
B20 = 1L << 20 ' 1,048,576
B21 = 1L << 21 ' 2,097,152
B22 = 1L << 22 ' 4,194,304
B23 = 1L << 23 ' 8,388,608
B24 = 1L << 24 ' 16,777,216
B25 = 1L << 25 ' 33,554,432
B26 = 1L << 26 ' 67,108,864
B27 = 1L << 27 ' 134,217,728
B28 = 1L << 28 ' 268,435,456
B29 = 1L << 29 ' 536,870,912
B30 = 1L << 30 ' 1,073,741,824
B31 = 1L << 31 ' 2,147,483,648
B32 = 1L << 32 ' 4,294,967,296
B33 = 1L << 33 ' 8,589,934,592
B34 = 1L << 34 ' 17,179,869,184
B35 = 1L << 35 ' 34,359,738,368
B36 = 1L << 36 ' 68,719,476,736
B37 = 1L << 37 ' 137,438,953,472
B38 = 1L << 38 ' 274,877,906,944
B39 = 1L << 39 ' 549,755,813,888
B40 = 1L << 40 ' 1,099,511,627,776
B41 = 1L << 41 ' 2,199,023,255,552
B42 = 1L << 42 ' 4,398,046,511,104
B43 = 1L << 43 ' 8,796,093,022,208
B44 = 1L << 44 ' 17,592,186,044,416
B45 = 1L << 45 ' 35,184,372,088,832
B46 = 1L << 46 ' 70,368,744,177,664
B47 = 1L << 47 ' 140,737,488,355,328
B48 = 1L << 48 ' 281,474,976,710,656
B49 = 1L << 49 ' 562,949,953,421,312
B50 = 1L << 50 ' 1,125,899,906,842,624
B51 = 1L << 51 ' 2,251,799,813,685,248
B52 = 1L << 52 ' 4,503,599,627,370,496
B53 = 1L << 53 ' 9,007,199,254,740,992
B54 = 1L << 54 ' 18,014,398,509,481,984
B55 = 1L << 55 ' 36,028,797,018,963,968
B56 = 1L << 56 ' 72,057,594,037,927,936
B57 = 1L << 57 ' 144,115,188,075,855,872
B58 = 1L << 58 ' 288,230,376,151,711,744
B59 = 1L << 59 ' 576,460,752,303,423,488
B60 = 1L << 60 ' 1,152,921,504,606,846,976
B61 = 1L << 61 ' 2,305,843,009,213,693,952
B62 = 1L << 62 ' 4,611,686,018,427,387,904
B63 = 1L << 63 ' -9,223,372,036,854,775,808
End Enum
I am looping through a card number finding all the odd numbers and multiplying them by the card digits. Its kind of hard to explain. I am having trouble multiplying the odd number and the card number. Here's an example my teacher gave me. You multiply card number 1 and and odd number 1 and so forth. I am not getting any errors, it just kind of freezes.
Sums
Card #: 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6
Multiples 1 2 3 4 5 6 7 8
Evens: 2 4 6 8 0 2 4 6 32 =Sum 1
Odds: 1 6 15 28 45 6 21 40 162 =Sum 2
Sum 3: 194
194 =Sum 3
Step 4: =1+9+4 = 14
= 1 + 4 = 5 = check digit
Public Class Payment
Private Sub OK_Click(sender As Object, e As EventArgs) Handles OK.Click
Dim Sum1 = 0
Dim Sum2 = 0
Dim Sum3 = 0
Dim ready As Boolean
Dim ccnumb = CardNumber.Text
Format(CardNumber.Text, "################")
Dim exp = Mid(ExpDate.Text, 1, 3)
Dim checkdigit = 0
If FullName.TextLength = 0 Or cardtype.Text.Length = 0 And ccnumb.Length <= 16 Or exp.Length = 2 Then
MessageBox.Show("Please enter all credit card information before proceeding.")
ready = False
Else ready = True
End If
If ready = True Then
For Each num As Char In ccnumb
If CInt(CStr(num)) Mod 2 <> 0 Then
Sum1 += CInt(CStr(num)) * CInt(CStr(num)) Mod 2 <> 0
Else
Sum2 += CInt(CStr(num))
End If
Next
Sum3 = Sum1 + Sum2
Do While Sum3 > 10
For j = 0 To Sum3.ToString.Length - 1
For k = 1 To Sum3.ToString.Length - 1
Sum3 = j + k
Next
Next
Loop
Do While exp.Length > 1
checkdigit = Mid(ExpDate.Text, 1, 1) + Mid(ExpDate.Text, 1, 2)
Loop
If Sum3 = checkdigit Then
MessageBox.Show("Congratulations! Your payment was successful.")
CustInv.Show()
Else MessageBox.Show("The checkdigit," & Space(1) & Sum3 & Space(1) & "does not match the month code," & Space(1) & checkdigit & "." & Space(1) & "Please reenter your card information.")
End If
End If
End Sub
"it kind of freezes" is lay speak for "my code enters an infinite loop".
This looks suspicious:
Do While Sum3 > 10
For j = 0 To Sum3.ToString.Length - 1
For k = 1 To Sum3.ToString.Length - 1
Sum3 = j + k
Next
Next
Loop
To enter the loop, Sum3 must be greater than 10. For the loop to exit, Sum3 must not be greater than 10, but your code only increments Sum3, so Sum3 can only stay greater than 10.
This means that once entered, this loop is infinite.
If changing outer loop to inside loop doesn't help you
Try this
Do While Sum3 > 10 and j < sum3 ' adding j < sum3 might stop the loop
For j = 0 To Sum3.ToString.Length - 1
For k = 1 To Sum3.ToString.Length - 1
Sum3 = j + k
Next
Next
Loop
If the numbers 1 to 5 are written out in words: one, two, three, four, five, then there are 3 + 3 + 5 + 4 + 4 = 19 letters used in total.
If all the numbers from 1 to 1000 (one thousand) inclusive were written out in words, how many letters would be used?
NOTE: Do not count spaces or hyphens. For example, 342 (three hundred and forty-two) contains 23 letters and 115 (one hundred and fifteen) contains 20 letters. The use of "and" when writing out numbers is in compliance with British usage.
my answer is coming 21148. i cant find the mistake here is my code in vb
the answer should be 21124
Dim length As UInt32 = 11
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
For i = 1 To 999
If i / 10 < 1 Then
single_digit(i)
ElseIf i / 10 = 1 Then
ten()
ElseIf i / 10 > 1 And i / 10 < 2 Then
ele_twe_thi(i)
ElseIf i / 10 >= 2 And i / 10 < 10 Then
multiple_10(Math.Floor(i / 10) * 10)
single_digit(i Mod 10)
ElseIf i = 100 Then
single_digit(i / 100)
length += 7
ElseIf i Mod 100 >= 11 And i Mod 100 <= 19 Then
length += 10
single_digit(Math.Floor(i / 100))
ele_twe_thi(i Mod 100)
ElseIf i Mod 100 = 10 Then
length += 3
single_digit(Math.Floor(i / 100))
length += 10
Else
length += 10
single_digit(Math.Floor(i / 100))
multiple_10(Math.Floor((i Mod 100) / 10) * 10)
single_digit(i Mod 10)
End If
Next
MsgBox(length)
End Sub
Private Sub single_digit(num)
If num = 1 Then
length = length + 3
ElseIf num = 2 Then
length = length + 3
ElseIf num = 3 Then
length = length + 5
ElseIf num = 4 Then
length = length + 4
ElseIf num = 5 Then
length = length + 4
ElseIf num = 6 Then
length = length + 3
ElseIf num = 7 Then
length = length + 5
ElseIf num = 8 Then
length = length + 5
ElseIf num = 9 Then
length = length + 4
End If
End Sub
Private Sub ele_twe_thi(num)
If num = 11 Or num = 12 Then
length = length + 6
ElseIf num = 13 Or num = 14 Or num = 18 Or num = 19 Then
length = length + 8
ElseIf num = 17 Then
length = length + 9
ElseIf num = 15 Or num = 16 Then
length = length + 7
End If
End Sub
Private Sub multiple_10(num)
If num = 20 Then
length = length + 6
ElseIf num = 30 Then
length = length + 6
ElseIf num = 40 Then
length = length + 5
ElseIf num = 50 Then
length = length + 5
ElseIf num = 60 Then
length = length + 5
ElseIf num = 70 Then
length = length + 7
ElseIf num = 80 Then
length = length + 6
ElseIf num = 90 Then
length = length + 6
End If
End Sub
Private Sub ten()
length = length + 3
End Sub
every time the program reaches 100, 200, 300 etc. is it adding an "and" unnecessarily?
I have a set of variables that holds quantity info and x to select the one I use. How can I concatenate the letter s and var x and have it read as s2 or s3 etc. The code I managed to find does not work.
x = 2
s1 = false
s2 = 64
s3 = 64
s4 = 64
s5 = 0
if s2 >= 0 then
x = 2
elseif s3 >= 0 then
x = 3
elseif s4 >= 0 then
x = 4
elseif s5 >= 0 then
x = 5
end
if turtle.placeDown() then
tryUp()
turtle.select(1)
_G["s"..x] = _G["s"..x] - 1
end
Why would you need to do that?
My suggestion to improve your code would be something like this:
local s = {false, 64, 64, 64, 0}
for i = 2, #s do
if s[i] >= 0 then
x = s[i]
end
end
if turtle.placeDown() then
tryUp()
turtle.select(1)
x = x-1
end
Using a loop makes the code somewhat neater, and there is no real need for you to use global variables. If you insist on using _G with the string concatenation with your original code, try this:
x = 2
s1 = false
s2 = 64
s3 = 64
s4 = 64
s5 = 0
if s2 >= 0 then
x = "2" --Notice the string here
elseif s3 >= 0 then
x = "3"
elseif s4 >= 0 then
x = "4"
elseif s5 >= 0 then
x = "5"
end
if turtle.placeDown() then
tryUp()
turtle.select(1)
_G["s"..x] = _G["s"..x] - 1
end
This replaces all the x values with strings instead of numbers, which was probably what was causing the error