-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFormMain.vb
More file actions
178 lines (155 loc) · 7.13 KB
/
Copy pathFormMain.vb
File metadata and controls
178 lines (155 loc) · 7.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
Public Class FormMain
Private Const Prog_Name As String = "Generate SendMany Text With Random Amounts"
Private m_sbMsg As New System.Text.StringBuilder()
Private m_rNum As New Random()
Private i As Integer = 0
Private m_iEnd As Integer = 0
Private m_dRndAmt As Double = 0.0
Private m_dTotalAmt As Double = 0.0
Private m_dMin As Double = 0.0
Private m_dMax As Double = 0.0
#Region "Form Events"
Private Sub FormMain_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.Icon = My.Resources.AirDrop_16_32_48_256
Me.Text = Prog_Name & " v" & My.Application.Info.Version.Major
Me.btnReGen.Text = ""
Me.btnReGen.Image = My.Resources.Reload_16.ToBitmap
Me.SplitContainer1.SplitterWidth = 2
End Sub
#End Region
#Region "Control Events"
Private Sub txtAddrList_TextChanged(sender As Object, e As EventArgs) Handles txtAddrList.TextChanged
GenerateText()
End Sub
Private Sub txtAmtMin_TextChanged(sender As Object, e As EventArgs) Handles txtAmtMin.TextChanged
GenerateText()
End Sub
Private Sub txtAmtMax_TextChanged(sender As Object, e As EventArgs) Handles txtAmtMax.TextChanged
GenerateText()
End Sub
Private Sub btnReGen_Click(sender As Object, e As EventArgs) Handles btnReGen.Click
GenerateText()
End Sub
Private Sub txtFromWallet_TextChanged(sender As Object, e As EventArgs) Handles txtFromWallet.TextChanged
GenerateText()
End Sub
Private Sub cboDecimalPlaces_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cboDecimalPlaces.SelectedIndexChanged
GenerateText()
End Sub
Private Sub txtComment_TextChanged(sender As Object, e As EventArgs) Handles txtComment.TextChanged
GenerateText()
End Sub
Private Sub cboDecimalPlaces_TextChanged(sender As Object, e As EventArgs) Handles cboDecimalPlaces.TextChanged
Select Case Me.cboDecimalPlaces.Text
Case "0", "1", "2", "4", "6", "8"
'Good
Case Else
'Correct any other text
Me.cboDecimalPlaces.Text = "6"
End Select
End Sub
#End Region
#Region "Keystroke Events"
Private Sub txtAddrList_KeyDown(sender As Object, e As KeyEventArgs) Handles txtAddrList.KeyDown
If e.Modifiers = Keys.Control Then
Select Case e.KeyCode
Case Keys.A
'CTRL+A select all text
Me.txtAddrList.SelectAll()
e.SuppressKeyPress = True
End Select
End If
End Sub
Private Sub txtOutput_KeyDown(sender As Object, e As KeyEventArgs) Handles txtOutput.KeyDown
If e.Modifiers = Keys.Control Then
Select Case e.KeyCode
Case Keys.A
'CTRL+A select all text
Me.txtOutput.SelectAll()
e.SuppressKeyPress = True
End Select
End If
End Sub
#End Region
#Region "Helper Functions"
Private Function FixStr(ByRef val As Double) As String
Select Case Me.cboDecimalPlaces.Text
Case "0"
Return val.ToString("0", Globalization.CultureInfo.InvariantCulture)
Case "1"
Return val.ToString("0.0", Globalization.CultureInfo.InvariantCulture)
Case "2"
Return val.ToString("0.00", Globalization.CultureInfo.InvariantCulture)
Case "4"
Return val.ToString("0.0000", Globalization.CultureInfo.InvariantCulture)
Case "6"
Return val.ToString("0.000000", Globalization.CultureInfo.InvariantCulture)
Case "8"
Return val.ToString("0.00000000", Globalization.CultureInfo.InvariantCulture)
Case Else
Return val.ToString("0.000000", Globalization.CultureInfo.InvariantCulture)
End Select
End Function
Private Function FixDbl(val As Double) As Double
Return Math.Round(val, CInt(Me.cboDecimalPlaces.Text), MidpointRounding.AwayFromZero)
End Function
#End Region
#Region "Generate Output Text"
Private Sub GenerateText()
'Reset for new output text
m_sbMsg.Length = 0
m_iEnd = 0
m_dRndAmt = 0.0
m_dTotalAmt = 0.0
m_dMin = 0.0
m_dMax = 0.0
Try
If Me.txtAddrList.Text.Length > 0 Then
If IsNumeric(Me.txtAmtMin.Text) = True AndAlso IsNumeric(Me.txtAmtMax.Text) = True Then
'Get the Min/Max range
m_dMin = CDbl(Me.txtAmtMin.Text)
m_dMax = CDbl(Me.txtAmtMax.Text)
If m_dMin <= m_dMax Then
If m_dMin >= 0.1 AndAlso m_dMax >= 0.1 Then
Me.txtOutput.BackColor = Color.FromKnownColor(KnownColor.Window)
Dim strAddr As String() = Me.txtAddrList.Text.Split(New String() {Environment.NewLine}, StringSplitOptions.RemoveEmptyEntries)
m_iEnd = strAddr.Length - 1
'Build the output text
m_sbMsg.Append("sendmany """ & Me.txtFromWallet.Text & """ ""{")
For i = 0 To m_iEnd
m_dRndAmt = FixDbl((m_rNum.NextDouble * (m_dMax - m_dMin)) + m_dMin)
'Add the new amount to the total
m_dTotalAmt += m_dRndAmt
'Trim out any extra spaces or commas from the address list while building the text string. Add the trailing comma for all entries except the last
m_sbMsg.Append("\""" & strAddr(i).Trim(","c, ";"c, " "c) & "\"":" & FixStr(m_dRndAmt) & If(i = m_iEnd, "", ","))
Next
m_sbMsg.Append("}"" 1 """ & Me.txtComment.Text & """")
'Display the output text
Me.txtOutput.Text = m_sbMsg.ToString
Else
Me.txtOutput.BackColor = Color.Tomato
Me.txtOutput.Text = "Please enter Min / Max values greater than 0.1"
End If
Else
Me.txtOutput.BackColor = Color.Tomato
Me.txtOutput.Text = "Please enter a Min value less than or equal to the Max value"
End If
Else
Me.txtOutput.BackColor = Color.Tomato
Me.txtOutput.Text = "Please enter valid Min / Max values above"
End If
Else
Me.txtOutput.BackColor = Color.Tomato
Me.txtOutput.Text = "Please add a list of addresses above"
End If
Catch ex As Exception
Me.txtOutput.BackColor = Color.Tomato
Me.txtOutput.Text = ex.ToString
End Try
'Display the Total Amount
Me.txtTotalAmt.Text = FixStr(m_dTotalAmt)
'Display the address count
Me.lblAddressList.Text = "Address List" & If(m_iEnd = 0, "", " (" & (m_iEnd + 1).ToString & ")") & ":"
End Sub
#End Region
End Class