Reverse Number in VB.Net - vb.net

I want Reverse Number: example:
Textbox1.Text = 2 14 21 22 34 44
a deployment algorithm to do this. make
Expected Output: All Combination possible Reverse.
2 41 21 22 34 44
2 14 12 22 34 44
2 14 21 22 43 44
2 14 21 22 34 44
2 41 12 22 34 44
2 41 12 22 43 44
and so on...
2 14 21 22 34 44
What I try: it works, but it does not carry all the possible combinations, as in the above model.
Dim r As Integer
Public Function Reverse(rn As Integer)
Dim value As Integer
Dim values As New List(Of String)
For Each strValue As String In TextBox1.Text.Split(" ".ToCharArray, StringSplitOptions.RemoveEmptyEntries)
If Integer.TryParse(strValue.Trim, value) Then
values.Add(value)
End If
Next
Dim numbers = Val(TextBox1.Text)
Dim result As Integer
While numbers > 0
rn = numbers Mod 10
result = result * 10 + rn
numbers = numbers \ 10
End While
Reverse = result
End Function
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
TextBox2.Text = Reverse(r & " ")
End Sub

Related

strword can be how can split used vbcrlf

How can split that items? I don't have anything else to do, which is what the textbox results look like and I don't know how to extract the values correctly from it.
Dim lines() As String = TxtResultToString1.Lines
For i As Integer = 1 To lines.Length - 1
Dim strWords = lines(i).Split(vbCrLf)
MsgBox(strWords(0))
Next
Items: this looks like it in the textbox
{ item = , Count = 1 }
{ item = 13, Count = 1 }
{ item = 17, Count = 1 }
{ item = 31, Count = 1 }
{ item = 5, Count = 1 }
{ item = 8, Count = 1 }
{ item = 77, Count = 2 }
{ item = 68, Count = 1 }
{ item = 21, Count = 1 }
{ item = 71, Count = 1 }
{ item = 40, Count = 1 }
{ item = 14, Count = 1 }
{ item = 49, Count = 1 }
{ item = 45, Count = 1 }
{ item = 29, Count = 1 }
{ item = 36, Count = 1 }
{ item = 44, Count = 1 }
In another textbox I want to do the following:
Textbox2.Lines=
13 17 31
17 31 5
31 5 8
8 77 68
68 21 71
21 71 40
71 40 14
40 14 49
14 49 45
49 45 29
45 29 36
29 36 44
First I parsed the lines in the text box to extract the item value. I split the line by the comma and then element (0) is split by the equals sign and trimmed. The result is add to the list. Then looping through the list I use a string builder to build the new lines. The minus 3 avoides an index out of range.
Private Sub ItemArrangement()
Dim lst As New List(Of String)
Dim lines = TextBox1.Lines
For i = 1 To TextBox1.Lines.Count - 1
Dim num = lines(i).Split(","c)(0).Split("="c)(1).Trim
lst.Add(num)
Next
Dim sb As New StringBuilder
For i = 0 To lst.Count - 3
sb.AppendLine($"{lst(i)} {lst(i + 1)} {lst(i + 2)}")
Next
TextBox2.Text = sb.ToString
End Sub
What you showed as output missed the line starting with 5. If this was intentional you will have to adjust the code.
My output in TextBox2 looked like this.
13 17 31
17 31 5
31 5 8
5 8 77
8 77 68
77 68 21
68 21 71
21 71 40
71 40 14
40 14 49
14 49 45
49 45 29
45 29 36
29 36 44

Eliminate Duplicate from a Textbox

I have Textbox1.Lines (separated by a space)
5 7 10 12 12
7 10 12 13 14
8 10 14 15 19
12 13 14 15 19
21 23 27 29 50
51 53 55 78 80
1 1 7 14 19
2 4 7 8 10
How should I remove duplicates from each line and display something like this:
7 10 12 13 14
8 10 14 15 19
12 13 14 15 19
21 23 27 29 50
51 53 55 78 80
2 4 7 8 10
that is, to remove from the entire line that contains a duplicate number on the same line.
Private Sub BttGamblerInput_Click(sender As Object, e As EventArgs) Handles BttGamblerInput.Click
On Error Resume Next
Dim value As Integer
Dim values As New List(Of String)
For Each strValue As String In TxtGamblerImput.Text.Split(" ".ToCharArray, StringSplitOptions.RemoveEmptyEntries)
If Integer.TryParse(strValue.Trim, value) Then
values.Add(value)
End If
Not worked.
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
For Each line In TxtGamblerOutput.Text
Dim originalArray = TxtGamblerOutput.Text.Split(" ".ToCharArray, StringSplitOptions.RemoveEmptyEntries)
Dim checkArray = originalArray.Distinct().ToArray() ' I haven't used this, so check syntax etc when you code it.
If originalArray.Length = checkArray.Length Then
TxtGamblerOutput.Text = checkArray
Else ' <-- perhaps a bonus here?
' Do something with the invalid line
End If
Next line
End Sub
Code 3:
Dim numbers() As Integer = {1, 3, 5, 7, 2, 1, 5, 4, 4, 8}
' get the duplicates
Dim dups As New Dictionary(Of Integer, Integer) ' number, count of number
For i = 0 To numbers.Length - 1
If dups.ContainsKey(numbers(i)) Then
dups(numbers(i)) += 1
Else
dups.Add(numbers(i), 1)
End If
Next
' display them
For Each dup In dups
If dup.Value > 1 Then
Console.WriteLine(dup.Key)
End If
Next
Console.ReadLine()
I haven't coded or tested anything, but you can use the Distinct method from List(of T) and compare the length of the output to the current List. Another approach is to use an ArrayList (c.f. https://stackoverflow.com/a/13428210/9101981 for the bones of getting unique elements).
Pseudo-ish Code using an Array:
for each line in the text input
originalArray = line.Text.Split(" ".ToCharArray, StringSplitOptions.RemoveEmptyEntries)
checkArray = originalArray.Distinct().ToArray() ' I haven't used this, so check syntax etc when you code it.
If originalArray.Length = checkArray.Length then
' Your code here to display the valid line
Else ' <-- perhaps a bonus here?
' Do something with the invalid line
End If
Next line
Some additional reading:
https://learn.microsoft.com/en-us/dotnet/api/system.collections.arraylist?view=netframework-4.8
and, in particular, note the recommendation to use List.
https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.distinct?view=netframework-4.8
noting that this is the Linq Distinct documentation

Convert big string to decimal in vb.net

Hello i have big string value which is md5 of something now i need to convert it into the decimal value
for example
Dim md5_s As String = "6F05AF42533432A5513610FE839ACC86"
now i need output same like the online converters to this
"54 70 48 53 65 70 52 50 53 51 51 52 51 50 65 53 53 49 51 54 49 48 70
69 56 51 57 65 67 67 56 54 "
is it possible i don't want spaces in the above converted decimal ?
vb.net help please
Okay here i tried and got it n is my approach works fine will this fine n work always right
Dim t As String
Dim a As String = "6F05AF42533432A5513610FE839ACC86"
For Each c As Char In a
t &= Convert.ToInt32(c)
Next
TextBox1.Text = t
will this one is right ?
result is same what i am looking for as
5470485365705250535151525150655353495154494870695651576567675654
so i assume this is right huh ?
I'm not quite sure this is what you are really looking for but this is what you asked for
For count = 0 To md5_s.Length - 1
Dim tempChar As String = md5_s.Substring(count, 1)
Console.Write(Asc(tempChar))
Next
What is more likely what you want is something like this
Private Function HexToByteArray(ByVal hex As [String]) As Byte()
Dim NumberChars As Integer = hex.Length
Dim bytes As Byte() = New Byte(NumberChars / 2 - 1) {}
For i As Integer = 0 To NumberChars - 1 Step 2
bytes(i / 2) = Convert.ToByte(hex.Substring(i, 2), 16)
Next
Return bytes
End Function
either way ... hope this helps

copy sets of numbers into a listbox from a textbox

I have a textbox that the user puts in sets of numbers(e.g. 32 45 98 56 52 1 23) and I need to copy these numbers into a listbox so that each number is its own item. So far I have this
For Each ch As Char In TextBox20.Text
If Char.IsDigit(ch) Then
ListBox1.Items.Add(ch)
End If
Next
but the problem is that it will copy each digit as an item so we will end up with
3
2
4
5
9
8
5
6
I need it to copy them like this
32
45
98
56
here is a sample of how to do that
Sub addToListBox()
Dim sample As String
Dim v As Variant
Dim i As Integer
sample = "32 45 98 56 52 1 23"
v = Split(sample, " ")
For i = 0 To UBound(v)
If IsNumeric(v(i)) Then
ListBox1.Items.Add(v(i))
End If
Next i
End Sub

how to tokenize chart data for csv file in classic asp

Hi below is the data sample for chart data which I read from URL
ARRAY ' ' 3 8
Y
25 75 100 125 150 175 200 225
'A' 3 8 6 7 5 3 2 7
'B' 1 9 7 8 4 7 2 5
'C' 8 7 3 6 56 9 111 8
Now in this I want to save this data into a csv file as below
Time A B c
25 3 1 8
75 8 9 7
100 6 7 3
125 7 8 9
150 5 4 56
175 3 7 9
200 2 2 111
225 7 5 8
Actually I have to first read the data into an array in which each element will contain one line of the data file, Now I will have to split the each element by space and store it in a two dimensional array, now for each ith index of each array I have to create a coma separated line then put "\n" at the end of line , and at last save this to a csv file . I don't know much about the syntax of vb-script and classic asp that's why I am facing this problem . Please help me
To get you started:
Sub doReOrder(sFSpecI, sFSpecO, sCol1)
Dim oTS : Set oTS = goFS.OpenTextFile(sFSpecI)
Dim sData : sData = oTS.ReadLine() ' ARRAY ' ' 3 8
Dim aParts : aParts = Split(sData, " ")
Dim nCols : nCols = CByte(aParts(3)) ' Count vs UBound vs Data!
Dim nRows : nRows = CByte(aParts(4))
Dim nRows2 : nRows2 = nRows + 1
oTS.SkipLine ' Y
' get table in one string, prepend col1 name, clean '
sData = "'" & sCol1 & "' " & Replace(oTS.ReadAll(), vbCrLf, " ")
sData = Trim(Replace(sData, "'", """"))
' get table in flat array
aParts = Split(sData, " ")
oTS.Close
Set oTS = goFS.CreateTextFile(sFSpecO, True)
' WScript.Echo Join(aParts, "|")
ReDim aData(nCols) ' hold one (new) row to prep for Join
Dim nRow
For nRow = 0 To nRows
Dim nCol
For nCol = 0 To nCols
' magic column hopping
aData(nCol) = aParts(nRow + nCol * nRows2)
Next
oTS.WriteLine Join(aData, ",")
Next
oTS.Close
End Sub
Test:
Dim sFSpecI : sFSpecI = "..\Data\f1.txt"
Dim sFSpecO : sFSpecO = "..\Data\f1.csv"
Dim sCol1 : sCol1 = "Time" ' dangerous - possibly reserved in SQL
WScript.Echo goFS.OpenTextFile(sFSpecI).ReadAll()
doReOrder sFSpecI, sFSpecO, sCol1
WScript.Echo goFS.OpenTextFile(sFSpecO).ReadAll()
Output:
ARRAY ' ' 3 8
Y
25 75 100 125 150 175 200 225
'A' 3 8 6 7 5 3 2 7
'B' 1 9 7 8 4 7 2 5
'C' 8 7 3 6 56 9 111 8
"Time","A","B","C"
25,3,1,8
75,8,9,7
100,6,7,3
125,7,8,6
150,5,4,56
175,3,7,9
200,2,2,111
225,7,5,8