Link to home
Create AccountLog in
Avatar of vonsean
vonseanFlag for United States of America

asked on

Barcode Font Replace Space with a UnderScore in VB.NET

Hello all i have been working on this project and i have almost finshed thanks to E.E. I have one last question that should finish up my project i just need to figure out when my users use the space bar it replaces it with a underscore ( _ ) i have all my code correct. Just need this last part figured out.

Thanks i am useing VB.NET Express not sure if this any help but i have been killing my self ont this simple loop issue any help would be greatly appreciated i have listed my code.

Thanks

Public Class scsdahill
    Private WithEvents mPrintDoc As New System.Drawing.Printing.PrintDocument()
 
 
 
 
 
 
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'UsersDataSet.Users' table. You can move, or remove it, as needed.
        Me.UsersTableAdapter.Fill(Me.UsersDataSet.Users)
 
        'ComboBox Drop down items listed here
 
        ComboBox2.Items.Add("San Antonio")
        ComboBox2.Items.Add("Harlingen")
        ComboBox2.Items.Add("Corpus Christi")
        ComboBox2.Items.Add("Laredo")
        ComboBox2.Items.Add("Houston")
        ComboBox2.Items.Add("Austin")
        ComboBox2.Items.Add("Dallas")
        ComboBox2.Items.Add("Bryan")
        ComboBox2.Items.Add("El Paso")
    End Sub
    Private Sub mPrintDoc_PrintPage(ByVal sender As Object, _
     ByVal e As System.Drawing.Printing.PrintPageEventArgs) _
     Handles mPrintDoc.PrintPage
 
        Dim timesRomanFont As New Font("TimesRoman", 25)
        Dim barcodeFont As New Font("Code39", 35)
 
 
 
 
 
 
        Dim X, Y As Int32
        X = 25        'Position of first character in line (Column)
        Y = 25        'Position of line (Row) 
 
        e.Graphics.DrawString("Scan Cover Sheet ", _
            timesRomanFont, Brushes.Black, X, Y, New StringFormat())
 
 
        Dim sText As String = "*a" & Me.ComboBox1.Text & "*" & vbCrLf & vbCrLf & _
        "*b" & Me.ComboBox2.Text & "*" & vbCrLf & vbCrLf & _
        "*c" & Me.TextBox1.Text & "*" & vbCrLf & vbCrLf & _
        "*d" & Me.TextBox2.Text & "*" & vbCrLf & vbCrLf & _
        "*e" & Me.TextBox3.Text & "*" & vbCrLf
 
 
 
 
 
        Y = 100 'Set new position of new row
 
        'Print using BarCode font
        e.Graphics.DrawString(sText, barcodeFont, Brushes.Black, X, Y, New StringFormat())
 
 
 
        sText = "User Name:" & Me.ComboBox1.Text & vbCrLf & _
        "Customer Name:" & Me.TextBox2.Text
 
        Y = 450 'Set new position of new row
        e.Graphics.DrawString(sText, _
            timesRomanFont, Brushes.Black, X, Y, New StringFormat())
 
 
    End Sub
 
    Private Sub btPrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btPrint.Click
        mPrintDoc.DefaultPageSettings.Landscape = True
        mPrintDoc.Print()
 
    End Sub
 
End Class

Open in new window

Avatar of AkisC
AkisC
Flag of Greece image

Your question: "i just need to figure out when my users use the space "

On form load type
MyBase.KeyPreview = True

    Private Sub Form_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
        If e.KeyCode = Keys.Space Then
            '//Space was pressed
        End If
    End Sub
Avatar of vonsean

ASKER

Hmm I input the code but i didnt see it make the changes i dont get a syntax error.
You have to write your code here
  '//Space was pressed
to replace space with _


ASKER CERTIFIED SOLUTION
Avatar of Howard Cantrell
Howard Cantrell
Flag of United States of America image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of vonsean

ASKER

Cool I will try it today, I have been out of town for the week. I will try it today I really appreceate all of the help from everyone.
I will try it tonight thanks again!!

Avatar of vonsean

ASKER

Sorry i didnt get it to work i get an error that i dont understand, maybe i did something wrong i copied the code to a blank form and i add my text boxs and so on then it removes them. Im not sure what i am doing wrong.
for this example you should not need any other code added to it.
Once you see how it runs you then can break up the parts and create your own form project.
Avatar of vonsean

ASKER

Thanks It worked i had to do some changes but i was able to figure out how to implement it in to my code.

Thanks!