hi i really need help, i m trying to write a program that displays in a textbox a talbe of the binary, octal, and hexadecimal equivalents of the decimal numbers in range 1-222.
Plz help i m new to vb....Thks you

Dani AI

Generated

Nice, practical approach from — using a monospaced TextBox and base conversions is the right direction. The posted String.Format has a small formatting mismatch (some placeholder indexes and the C format specifier were used incorrectly — C is the currency formatter), so the output can come out wrong even though the conversion calls themselves are fine.

A cleaner pattern is: build the text with a StringBuilder, emit a simple header row, convert each value explicitly (use n.ToString("X") for hex or Convert.ToString(n, base) for binary/octet), and pad binary to a fixed width for readable columns. Example (VB.NET):

Dim sb As New System.Text.StringBuilder()

sb.AppendLine(String.Format("{0,6} {1,8} {2,6} {3,10}", "Dec", "Hex", "Oct", "Bin"))

For n As Integer = 1 To 222
    Dim decS = n.ToString()
    Dim hexS = n.ToString("X")
    Dim octS = Convert.ToString(n, 8)
    Dim binS = Convert.ToString(n, 2).PadLeft(8, "0"c)
    sb.AppendLine(String.Format("{0,6} {1,8} {2,6} {3,10}", decS, hexS, octS, binS))
Next

TextBox1.Font = New System.Drawing.Font("Courier New", 10)
TextBox1.Multiline = True
TextBox1.WordWrap = False
TextBox1.ScrollBars = ScrollBars.Vertical
TextBox1.Text = sb.ToString()

Notes and troubleshooting:

  • Fixed-width alignment requires a monospaced font (Courier New) and WordWrap = False.
  • PadLeft is useful for consistent binary column width (here 8 bits for values ≤255).
  • For larger ranges or sortable/filterable display, use a DataGridView or ListView (Details view) rather than a big TextBox.
  • For small ranges (1–222) string concatenation is okay, but StringBuilder scales much better.

This keeps the table neat and avoids the format-specifier/index errors seen earlier; it will produce readable decimal, hex, octal and binary columns for ’s requested range.

Recommended Answers

All 3 Replies

Dim sTemp As String = ""
        TextBox1.Multiline = True
        TextBox1.Dock = DockStyle.Fill
        TextBox1.ScrollBars = ScrollBars.Vertical
        TextBox1.Font = New System.Drawing.Font("Courier New", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))

        For i As Integer = 1 To 222
            sTemp = sTemp & String.Format("{0,6} {0, 10:X} {1, 10:C} {2, 10:C}", i, Convert.ToString(i, 8), Convert.ToString(i, 2)) & vbCrLf

        Next
        TextBox1.Text = sTemp

thanks you very much,, i will try this .......

thks lot it works.....

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.