|
I have a VB 6 app that I have rewritten in VB .Net from VS 2010 framework 4. The examples that I've seen from Zebra show the following
Dim SA As SECURITY_ATTRIBUTES
Dim outFile As FileStream, hPortP As IntPtr
LPTPORT = "LPT1"
Texxxt = Me.RichTextBox1.Text
hPort = CreateFile(LPTPORT, GENERIC_WRITE, FILE_SHARE_WRITE, SA, OPEN_EXISTING, 0, 0)
hPortP = New IntPtr(hPort) 'convert Integer to IntPtr
outFile = New FileStream(hPortP, FileAccess.Write, False) 'Create FileStream using Handle
Dim fileWriter As New StreamWriter(outFile)
fileWriter.Write("^XA^FO50,50^A030,30^FD ZEBRA^FS")
This gives me this
'Public Sub New(handle As System.IntPtr, access As System.IO.FileAccess)' is obsolete: 'This constructor has been deprecated. Please use new FileStream(SafeFileHandle handle, FileAccess access) instead.
When I use SafeFileHandle in XP I can print but in Win 7 I get this
{"Invalid handle.Parameter name: handle"}
Here is my code
Public Structure SECURITY_ATTRIBUTES
Private nLength As Integer
Private lpSecurityDescriptor As Integer
Private bInheritHandle As Integer
End Structure
Public Declare Function CloseHandle Lib "kernel32" Alias "CloseHandle" (ByVal hObject As Integer) As SafeFileHandle
Public Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" ( _
ByVal lpFileName As String, _
ByVal dwDesiredAccess As Integer, _
ByVal dwShareMode As Integer, _
<marshalas(unmanagedtype.struct)> ByRef lpSecurityAttributes As SECURITY_ATTRIBUTES, _
ByVal dwCreationDisposition As Integer, _
ByVal dwFlagsAndAttributes As Integer, _
ByVal hTemplateFile As IntPtr) As SafeFileHandle
Dim COMPORT As String
Dim hPort As SafeFileHandle
Dim SA As SECURITY_ATTRIBUTES
Dim outFile As FileStream
COMPORT = "COM4"
hPort = CreateFile(COMPORT, GENERIC_WRITE, FILE_SHARE_WRITE, SA, OPEN_EXISTING, 0, 0)
outFile = New FileStream(hPort, FileAccess.Write, 8, False)
Dim fileWriter As New StreamWriter(outFile)
fileWriter.Write("^XA") ' Start format
the invalid handle is hPort. Does anyone have an answer and how to correct? TIA
Ed Mee
|
|
|
|
|
You cannot open LPT1 like that. The code sample you found will only work on Windows 9x.
There's another way to do it here[^].
|
|
|
|
|
I found an easier solution. I'm using the SerialPort class.
Dim ComSerialPort As SerialPort
ComSerialPort = New SerialPort("COM4", 9600, Parity.None, 8, StopBits.One)
ComSerialPort.Open()
'Setup Media profile then print
For i1 = 1 To (Conversion.Val(txtPartQty.Text) * Conversion.Val(txtBandQty.Text)) Step 1
ComSerialPort.WriteLine("^XA") ' Start format
ComSerialPort.Write(strLL) ' Sets Label length
ComSerialPort.Write("^POI") ' Print orientation inverted 180 degrees
If optPlastic.Checked Then
ComSerialPort.Write("^MD25") ' Media darkness for plastic
End If
For i2 As Integer = 1 To intLines Step 1
ComSerialPort.Write(strLine(i2 - 1))
Next i2
ComSerialPort.Write("^XZ")
Next i1
ComSerialPort.Close()
Ed Mee
|
|
|
|
|
Your original code said LPT port, but I didn't see the COM port designation in the second code snippet. Over serial, this is much easier to do.
|
|
|
|
|
Hi,
Actually i converted my Vb.Net2008 project to 2010. But after to the convertion everything goes fine except SQLDMO.
I used the below code to create a backup & rename & restore in in the same server... And this can be useful at yearend backup like
database name "My_Procurement_Db" can be restored as "My_Procurement_Db_2010".....
The codes I used
Dim backup As Microsoft.SqlServer.SQLDMO.Backup = New SQLDMO.BackupClass()
Dim oServer As SQLDMO.SQLServer = New SQLDMO.SQLServerClass()
oServer.LoginSecure = True
oServer.Connect("198.198.3.90", "sa", "123")
backup.Action = SQLDMO.SQLDMO_BACKUP_TYPE.SQLDMOBackup_Database
backup.Database = "My_Procurement_Db"
backup.Files = PurDbName
backup.BackupSetName = "Procurement_Analysis"
backup.BackupSetDescription = "Database Backup Description"
backup.Initialize = True
backup.SQLBackup(oServer)
'RESTORE PROCESS STARTED
Dim oRestore As SQLDMO.Restore
Dim qRest As SQLDMO.QueryResults
Dim LDNames(1) As String
oRestore = New SQLDMO.Restore
With oRestore
.Database = "My_Procurement_db_2010"
.Action = SQLDMO.SQLDMO_RESTORE_TYPE.SQLDMORestore_Database
.ReplaceDatabase = True
.Files = PurDbName
qRest = .ReadFileList(oServer)
LDNames(0) = qRest.GetColumnString(1, 1)
LDNames(1) = qRest.GetColumnString(2, 1)
.RelocateFiles = "[" & LDNames(0) & "],[D:\test.mdf]" _
+ ",[" & LDNames(1) & "],[D:\testlog.ldf]"
.SQLRestore(oServer)
End With
oRestore = Nothing
oServer.DisConnect()
oServer = Nothing
Any Ides For Me ?
Thanks & Regards
PARAMU
|
|
|
|
|
Whats the problem?
Isn't it working as expected? if so what does it do and what should it do
Error messages?
As barmey as a sack of badgers
Dude, if I knew what I was doing in life, I'd be rich, retired, dating a supermodel and laughing at the rest of you from the sidelines.
|
|
|
|
|
Paramu1973 wrote: Any Ides For Me ?
Yes, beware of March.
I don't speak Idiot - please talk slowly and clearly
'This space for rent'
Driven to the arms of Heineken by the wife
|
|
|
|
|
Hello, Everyone, I am a newer with Visual Basic 2008. There is a question with me.
I have a Database Named: PasswordData.sdf, it has two tables in it, one is: TableDetail, another is TableUser. TableDetail have some IDs in it, for example: Customer Name, TableUser have three IDs in it: UserName, Password, UserType.
There are two Forms, one is Login Form, it have User Name TextBox, Password TextBox and UserType Textbox. The other is Main Form, it have Customer Name TextBox, Customer Sex TextBox, Customer Address TextBox and so on.
I want to write some codes with VB2008, but I don't know. Could you help me?
Thank you So much!
Jacky Shen
|
|
|
|
|
dzhello wrote: I want to write some codes with VB2008, but I don't know. Could you help me?
On the surface, this may sound like a stupid question, but write code to do WHAT?
|
|
|
|
|
MSDN: Development for beginners[^]
I would start looking at these articles / references to begin with
As barmey as a sack of badgers
Dude, if I knew what I was doing in life, I'd be rich, retired, dating a supermodel and laughing at the rest of you from the sidelines.
|
|
|
|
|
How do I code the price function for the prices of each checked boxes and radio buttons to show in the total label? I have decided that if no one is going to help me with this project, then I will drop the class with a W.
If anyone wants to see my graphical user interface, I will send it to you. Thank you for your help geniuses! I will say good things about you in heaven.
Public Class Form1
Private Sub exitButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles exitButton.Click
Me.Close()
End Sub
Private Sub newOrderButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles newOrderButton.Click
' clears all the information that is displayed and start over
nameTextBox.Text = String.Empty
addressTextBox.Text = String.Empty
telephoneTextBox.Text = String.Empty
viewCheckBox.Checked = False
bedCheckBox.Checked = False
jacuzziCheckBox.Checked = False
breakfastCheckBox.Checked = False
internetCheckBox.Checked = False
mattressCheckBox.Checked = False
sealyRadioButton.Checked = False
sertaRadioButton.Checked = False
simmonsRadioButton.Checked = False
regularRadioButton.Checked = False
executiveRadioButton.Checked = False
suiteRadioButton.Checked = False
cashRadioButton.Checked = False
visaTextBox.Text = String.Empty
visaTextBox.Enabled = False
visaRadioButton.Checked = False
mastercardTextBox.Text = String.Empty
mastercardTextBox.Enabled = False
mastercardRadioButton.Checked = False
checkTextBox.Text = String.Empty
checkTextBox.Enabled = False
checkRadioButton.Checked = False
nameTextBox.Focus()
End Sub
Private Sub orderButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles orderButton.Click
Dim regular As Double
Dim total As Double
Double.TryParse(regularRadioButton.Checked, regular)
If regularRadioButton.Checked Then
totalLabel.Text = total + 199.5
ElseIf executiveRadioButton.Checked Then
totalLabel.Text = total + 375.0
ElseIf suiteRadioButton.Checked Then
totalLabel.Text = total + 495.99
End If
If viewCheckBox.Checked Then
totalLabel.Text = total + 250.0
ElseIf bedCheckBox.Checked Then
totalLabel.Text = total + 70.0
ElseIf jacuzziCheckBox.Checked Then
totalLabel.Text = total + 199.0
ElseIf breakfastCheckBox.Checked Then
totalLabel.Text = total + 30.0
ElseIf internetCheckBox.Checked Then
totalLabel.Text = total + 19.99
ElseIf mattressCheckBox.Checked Then
totalLabel.Text = total + 55
totalLabel.Text = total + 45.0
totalLabel.Text = total + 35.0
End If
messageLabel.Text = "You have placed an order for" & ControlChars.NewLine & ControlChars.NewLine
If regularRadioButton.Checked Then
order = "Regular ($199.50)"
ElseIf executiveRadioButton.Checked Then
order = "Executive ($375.00)"
ElseIf suiteRadioButton.Checked Then
order = "Suite (495.99)"
End If
totalLabel.Text = total.ToString("C2")
End Sub
Private Sub cashRadioButton_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cashRadioButton.CheckedChanged
If cashRadioButton.Checked Then
visaTextBox.Enabled = False
End If
If cashRadioButton.Checked Then
mastercardTextBox.Enabled = False
End If
If cashRadioButton.Checked Then
checkTextBox.Enabled = False
End If
If visaRadioButton.Checked Then
visaTextBox.Enabled = True
End If
If mastercardRadioButton.Checked Then
mastercardTextBox.Enabled = True
End If
If checkRadioButton.Checked Then
checkTextBox.Enabled = True
End If
End Sub
|
|
|
|
|
Inside orderButton_Click() the total isn't changing at all;
a sequence of statements such as totalLabel.Text = total + 19.99 is modifying what can be seen in the totalLabel label, it doesn't do anything to the total variable. And the GUI will only show the outcome of the last assignment to totalLabel.Text
What you should have is like so:
Dim total As Double = 0
If ... Then
total = total + 199.5
If ... Then
total = total + 370
...
totalLabel.Text = total.ToString("C2")
That way, the total variable starts at a known value (zero), and increases by accumulating the selected prices. Note how the totalLabel control is used only once, to display the result, when all calculations have finished.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
And replace the content of your cashRadioButton_CheckedChanged method with this one:
vistaTextBox.Enabled = visaRadioButton.Checked
mastercardTextBox.Enabled = mastercardRadioButton.Checked
checkTextBox.Enabled = checkRadioButton.Checked
So many If statements are really confusing for just enabling a control when its option is selected.
|
|
|
|
|
how can we generate data report in visual basic and hw can we have the print of it
|
|
|
|
|
This can be considered - http://www.vbtutor.net/vb6/lesson40.html[^].
The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it.
|
|
|
|
|
|
I have a task that is being repeated throughout the application many times. My goal is to take those methods and consolidate it into a Global method.
The problem I am running into is that each task uses a different class type.
My thoughts were to create a method, say IncrementLine(), passing in as a parameter an Enum that would tell it what class it is coming from (Rooms or Library for instance).
This is an example of the existing code from one of these methods: (Also this is the exact code I need to change to bring back different classes, instead of RoomData it could be LibraryData - instead of Room it could be Library)
Dim lstRooms As List(Of RoomData) = Room.LoadAllForLibrary(libraryID)
The code for each of my methods that call IncrementLine() have their own classes like RoomData and Room. With the exception of the code above the rest of the method codes are identical.
Without using a bunch of Selects to determine what Class I should use..how can I return the proper class based on the enum passed in?
I was thinking of maybe using a Generic Delegate Class..something like this:
Public Function ReturnClass(Of t)(ByVal _lType As ListType) As t
End Function
based on what enum value they place it would send back the correct class..however, once I created this class I realized I'd still have to do a Select to determine what ListType they provided.
So my question is, how can I change the code above to be dynamic in returning the proper class based on the enum?
Thanks
|
|
|
|
|
sir;
i think that you need to use Type.GetConstructor() to return an instance of the appropriate type.
Good Luck;
Help people,so poeple can help you.
|
|
|
|
|
Another alternative would be using the Activator , as described here[^].
I are Troll
|
|
|
|
|
Good alternative, Sir.
100
Help people,so poeple can help you.
|
|
|
|
|
I agree great solution, thank you both for the time on this.
|
|
|
|
|
Hi all,
I have a database where the data contains some special chars.
I retrive the data from the dbase (dbf) file with a sql statement and write it into a text file using vb.net.
When I write the text file some of the special characters are not written the same way as in the dbf file, its written as a box.
I'm using:
<br />
Using sw As StreamWriter = New StreamWriter(dbfFile, False, System.Text.Encoding.Default)<br />
while writing to text file.
I'm not sure how to read the exact data from the database.
Is there a special way to do that???
Thanks in advance for anyh suggestion and help.
|
|
|
|
|
if you want to use characters outside the ASCII set, you need either a specific "code page" (not my recommendation) or 16-bit characters (Unicode).
what field type are you using in the database? it should be nvarchar or ntext in most databases for Unicode.
and then better specify Encoding.Unicode explicitly, both when writing to and reading from the database.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
he wrote about dbf (dbase) files ... no nvarchar, only fixed size char fields. in dbf files, the application has to take care of the correct codepage (you can nearly write everything in a dbf char field, except the 0 char).
I cannot remember: What did I before google?
|
|
|
|
|
The linefeed(LF) character is written as a box.
If i have a line feed, i want to ignore it...
ie; ignore only (LF) and not CRLF.
Thanks for any solution.
|
|
|
|
|