|
Your code is really difficult to understand. You should modify your message and use <pre> tags to format the code to make it readable.
Paul Marfleet
|
|
|
|
|
As Paul already said, please use the <pre> tags when posting large blocks of code like this.
The problem is that the InputBox method returns a String value and there is not an implicit conversion between a String and a Short . Your best best is to do something like this:
Dim securityCodeInput As String
Dim lngCode As Short
Dim returnValue As Boolean
securityCodeInput = InputBox("Insert code to code the file.")
returnValue = ShortInt16.TryParse(securityCodeInput, lngCode) The TryParse will return false if the input was not numeric and lngCode will be 0; otherwise, it will return true and lngCode will be the numeric value.
Also, you really should consider not using the Hungarian style notation for variable names. Since .NET is a strongly typed language it isn't really adding any value to your code. Especially in this case, since your variable name already doesn't match your data type. lngCode implies that it is a Long data type when in reality it is a Short .
[modification]Sorry, the Short.TryParse should have been Int16.TryParse .[/modification]
|
|
|
|
|
I am trying to send a data to the printer when i click a button.
I donot want to print. only send the data to the printer.
I need to send this text to the printer: @PJL REGISTRATION=1000000000. Like this i have 10 lines of text.
Here is the code i am using:
option Explicit
Private Type DOCINFO
pDocName As String
pOutputFile As String
pDatatype As String
End Type
Private Declare Function ClosePrinter Lib "winspool.drv" (ByVal _
hPrinter As Long) As Long
Private Declare Function EndDocPrinter Lib "winspool.drv" (ByVal _
hPrinter As Long) As Long
Private Declare Function EndPagePrinter Lib "winspool.drv" (ByVal _
hPrinter As Long) As Long
Private Declare Function OpenPrinter Lib "winspool.drv" Alias _
"OpenPrinterA" (ByVal pPrinterName As String, phPrinter As Long, _
ByVal pDefault As Long) As Long
Private Declare Function StartDocPrinter Lib "winspool.drv" Alias _
"StartDocPrinterA" (ByVal hPrinter As Long, ByVal Level As Long, _
pDocInfo As DOCINFO) As Long
Private Declare Function StartPagePrinter Lib "winspool.drv" (ByVal _
hPrinter As Long) As Long
Private Declare Function WritePrinter Lib "winspool.drv" (ByVal _
hPrinter As Long, pBuf As Any, ByVal cdBuf As Long, _
pcWritten As Long) As Long
Private Sub Command1_Click()
Dim lhPrinter As Long
Dim lReturn As Long
Dim lpcWritten As Long
Dim lDoc As Long
Dim sWrittenData As String
Dim MyDocInfo As DOCINFO
lReturn = OpenPrinter(Printer.DeviceName, lhPrinter, 0)
If lReturn = 0 Then
MsgBox "The Printer Name you typed wasn't recognized."
Exit Sub
End If
MyDocInfo.pDocName = "AAAAAA"
MyDocInfo.pOutputFile = vbNullString
MyDocInfo.pDatatype = vbNullString
lDoc = StartDocPrinter(lhPrinter, 1, MyDocInfo)
Call StartPagePrinter(lhPrinter)
lReturn = EndPagePrinter(lhPrinter)
lReturn = EndDocPrinter(lhPrinter)
lReturn = ClosePrinter(lhPrinter)
End Sub
|
|
|
|
|
You copied the example off of MSDN exactly, except for the two lines that actually sent the data:
sWrittenData = "How's that for Magic !!!!" & vbFormFeed
lReturn = WritePrinter(lhPrinter, ByVal sWrittenData, _
Len(sWrittenData), lpcWritten)
In you're case, that would be:
sWrittenData = "@PJL REGISTRATION=1000000000" & vbCrLf
lReturn = WritePrinter(lhPrinter, ByVal sWrittenData, _
Len(sWrittenData), lpcWritten)
|
|
|
|
|
Thanks Dave, I copied from MSDN. But i have a problem here. I have some ASCII charcters in my text. Instead i want to send the file when i click on the button. How will i do that. I need to include the file part of the exe.
I am new to VB.
Thanks
|
|
|
|
|
jkonduru wrote: Instead i want to send the file when i click on the button. How will i do that
So?? Read the file line-by-line and send each line to the using the same method in those two lines you missed.
|
|
|
|
|
some of the lines are in ASCII Characters, cannot be readable. Instead of reading line by line, is it possible specify that file name and send the file to the printer. Is it possible to include the file part of the project?
Thanks
|
|
|
|
|
jkonduru wrote: some of the lines are in ASCII Characters
So??
jkonduru wrote: cannot be readable
By a human that is. The file operations have no problem with it.
jkonduru wrote: Instead of reading line by line, is it possible specify that file name and send the file to the printer.
No. You're code has to open the file, and read a line, send it, read a line, send it, read a line, read it, ..., until the end of the file. VB6 doesn't do this for you. You have to write the code to do it.
jkonduru wrote: Is it possible to include the file part of the project?
It would just be a "content" file. It won't get compiled into the application. I forgot how to include that stuff in the Setup and Deployment wizard. It's been over 6 years since I abandoned my support for VB6.
|
|
|
|
|
jkonduru wrote:
Instead of reading line by line, is it possible specify that file name and send the file to the printer.
No. You're code has to open the file, and read a line, send it, read a line, send it, read a line, read it, ..., until the end of the file. VB6 doesn't do this for you. You have to write the code to do it.
Jkonduru: reply: How will i do this then?
|
|
|
|
|
jkonduru wrote: How will i do this then?
This is basic stuff...
Open "filename" for Input As #1
While Not EOF(1)
Line Input #1, s
' Write the contents of "s" out to printer here...
Wend
Close #1
Google results for "vb6 open file and read[^]".
|
|
|
|
|
Hi:
I would like about if exist a method for change any form from ms access to design view using vba code, the ms access's forms have a context menu with one option called "Change to design view", i want can change to this view from code, is possible?, thanks for your help.
|
|
|
|
|
This question really is geared more towards a forum specifically for supporting Access. This has far more to do with the Access object model than VBA. As far as I can tell, there's no way to switch a form to Desgin view. According to the ViewsAlloed property, it only supports Forms and Datasheet views. There is no option to allow Design view from code.
|
|
|
|
|
Oh, well, thanks for your help
|
|
|
|
|
Does .NET offer a licensing program. I want to use licensing to lock out and unlock my program. Is there a easy way to do this in .Net or will I need a 3rd party software? I searched Google and did not find anything for .Net.
|
|
|
|
|
There is nothing in the .NET BCL to do this, nor should there be. It has to be done either with your own custom implementation or using a 3rd party solution. Either way, it only slows people down from pirating your stuff. Nothing will stop them completely.
Google for "VB.NET licensing" and you'll come up with a bunch of solutions. I hear Aspose has got a good one, though I don't bother with licensing.
|
|
|
|
|
Hi all, Not to sure where I can Find the remoting thread so forgive me for posting under general.
I am currently trying to figure out how remoting works with datasets. Here are the steps taken
1) Created an interface wich will sit on the clients machine and reference the classes
2) Created the implements classes on the server app for the interface
3) Setup the server channels and communication
4) Created a small function that will test the connection
5) Added a database using the designer ... this created an xsd file dataset.
Right ... now everything works fine, the test runs smoothly and the client server talk to eachother. If I create a Dataset with a dataadaptor.fill and the server request the function it works fine and populates a datagrid on the other side.
The Working way.....
Public Function GetData() As System.Data.DataSet Implements IShared.IShared_Interface.GetData<br />
Dim Conn As New OleDbConnection<br />
Dim ConStr As String<br />
ConStr = "Provider=Microsoft.Jet.OLEDB.4.0;"<br />
ConStr += ConnStr<br />
ConStr += "Persist Security Info=True;"<br />
Conn.ConnectionString = ConStr<br />
Dim add As New OleDbDataAdapter("Select * From ClientInfo", Conn)<br />
Dim Dt As New DataTable<br />
add.Fill(Dt)<br />
Dim Ds As New DataSet<br />
Ds.Tables.Add(Dt)<br />
Return Ds<br />
End Function
I hoped that there was a better way to do this then started experimenting, hence step 5.
The designer sets up the database, datasets, dataadapters all nicely in the xsd file, but ... when the client request the dataset it has an incorrect assembly
Unable to find assembly 'AssemblyName, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.
The Not Working way ....
Public Function GetDataAnotherWay() As System.Data.DataSet Implements IRMSShared.IRMSShared_Interface.GetDataAnotherWay<br />
Dim Ds As New DataBaseDataSet<br />
Return Ds<br />
End Function
Please could someone help me out here, I would think that the second example would be much easier but it is not. I have look at the seialization techniques, but seems like a very long way round ... might as well just code all the datasets and dataadaptors.
If any one knows a link to examples of how to use a Typed Dataset in remoting through an interface please let me know. I have been battling at this for some time. I will even email the full source code. It is written with vs 2008 beta 2, but I am using the framwork 2.
Thanks
Go Springboks
-- modified at 14:33 Tuesday 23rd October, 2007
|
|
|
|
|
I haven't used 2008 very much, and surely not doing any remoting with datasets, but...
In your first example, you're returning a DataSetObject, in the second sample, you're returning an Object. I also don't have any clue what a "DataBaseDataSet" object is, so there's no way to tell what it's implementation is or if it supports serialzation, ...
|
|
|
|
|
Hi Dave
Apologies for the crappy code in the second function, I was testing to see what type of object is actually created. The object is meant to be a datasetobject.
DataBaseDataSet a class of the Typed Dataset that the designer creates when the database is added to the project, it could be any name. It has the same name as the xsd file which references the database.
VS 2008 is pretty cool and look forward to it's launch. The reason for 2008 is I upgraded to Vista and VS 2003 does not run on that, which I used to code in. Wasn't going to purchase vs 2005 if 2008 is replacing it in a few months. Things are expensive here in good SA.
I see that you have not remoted datasets in your apps, have you created some apps that use data on a client machine. Is there another way around this.
Thanks for the response
|
|
|
|
|
RG_SA wrote: I see that you have not remoted datasets in your apps
No, I said I haven't done it under all the designer generated crap of VS2008. I normally don't use the designer generated stuff...
I HAVE remoted DataSet's with my own code under 2005. Since a DS is easily serializable under XML, there's no problem. An instance of an Object is not serializable, even if it's a wrapper for a serializable object. If the function returned an object that inherited from DataSet, it shouldn't be an issue.
OK. The original post changed. The error you're getting is probably caused by the interface definition not being found. Is the assembly that defines the interface in the folder from where the server .EXE was launched?? Are you returning an implementation of that interface?? Is the assembly for that definition in the server .EXE's folder?? Do the assembly version numbers match what the server .EXE was compiled against?? That's usually what causes the error you're getting.
-- modified at 15:34 Tuesday 23rd October, 2007
|
|
|
|
|
I have a TCP/IP server (VB .net 2.0 Windows App) that accepts connections from clients receives a string from them and passes back an answer. The TCP/IP Server creates a thread for each connection and that thread handles that connection then terminates. Each of these connection threads increments a counter class when it starts and decrements it when it finishes. The main thread in the TCP/IP server program queries the value of the counter class periodically to see how many threads are being handled at that time. This is working perfectly and has been for well over a year.
Now, I need to share the value of this counter with other programs. In specific we are going to start using Microsoft's System Center Manager to monitor and alert of potential problems etc. After a discussion with my Boss it is clear that he would like a way to reach into my program and pull this value vs. having my program write it to an environment variable or even a file that could be read. I think this should be doable but I'm not sure exactly what I should be looking to do. Keep in mind the TCP/IP server is a Windows App. Any advise would be appreciated.
|
|
|
|
|
There's a bunch of different ways of doing this, depending on your environment. Probably the best way to do it is to change the server code to expose the number you were talking about as a PerformanceCounter. Other programs can then use the performance counter information to get the current count.
An Introduction To Performance Counters[^]. The code is in C#, but is easily translatable to VB.NET.
|
|
|
|
|
Is the performance counter the same thing as WMI?
|
|
|
|
|
Nope. But WMI has it's option too, where you're able to create a custom class to do this. It's more work than creating a PerformanceCounter implementation though.
|
|
|
|
|
Ok, I just spoke with my boss and he's still deciding on what monitoring package to use so I kind of need to wait until I see what it is capable of reading now. I appreciate all your help.
|
|
|
|
|
hi frnds,
i am using Visual basic DOM
my XML is like
<study>
<subject id="1">
<sub-topic> fast </sub-topic>
</subject>
<subject id="2">
<sub-topic> fast1 </sub-topic>
</subject>
</study>
i have to remove all the <sub-topic> node and insert them before the
<subject id="1"> tag
i have do the code...But can't supported pl...show me the way
here is my code
[CODE]
oNodeStudyList = objdom.getElementByTagName("study")
oNodeList = objdom.getElementByTagName("subject")
dim i as integer
dim iCount as integer
for iCount = 0 to oNodeStudyList.Length -1
for i = 0 to oNodeList.length -1
Set oNode = oNodeList(i)
if oNode.haschildnodes then
Set oDemoNode = Node.InsertBefore(node.childnode(0),oNodeStudyList.childnode(0))
end if
next
next
[/CODE]
first <sub-topic> will be added successfully
but then it can't find the second the <sub-topic>
where i am wrong....?
please help...
regards,
koolprasad2003
Be a good listener...Because Opprtunity knoughts softly...N-Joy
|
|
|
|
|