|
I ran into something simular last year and I think the problem was that you have to 'show' the form before setting the borders:
aransiola wrote: dim myForm as New Invoice
myForm.show
myForm.left = listview.left
myForm.top=listview.top
If my help was helpfull let me know, if not let me know why.
The only way we learn is by making mistakes.
|
|
|
|
|
The code as shown below worked for non-modal window form
but did not position modal window forms. even setting the cordinates before showing the window form
dim myForm as New Invoice
myForm.show
myForm.left = listview.left
myForm.top=listview.top
any further discoveries to positioning modal forms will be appreciated.
thanks
thank u
t.aransiola
|
|
|
|
|
Hi,
I got a downloader program form internet but it was made in C# . I converted it to VB.NET . There is no errors in the code , but it isn't working ! Here is the few code form the whole project which is not working:
Imports System.IO<br />
Imports System.Net<br />
Imports System.Text<br />
Imports System<br />
Imports System.Collections.Generic<br />
Imports System.ComponentModel<br />
Imports System.Data<br />
Imports System.Drawing<br />
<br />
Imports System.Windows.Forms<br />
<br />
Imports System.Threading<br />
Public Class Download<br />
Private thrDownload As Thread<br />
' The stream of data retrieved from the web server<br />
Private strResponse As Stream<br />
' The stream of data that we write to the harddrive<br />
Private strLocal As Stream<br />
' The request to the web server for file information<br />
Private webRequest As HttpWebRequest<br />
' The response from the web server containing information about the file<br />
Private webResponse As HttpWebResponse<br />
' The progress of the download in percentage<br />
Private Shared PercentProgress As Integer<br />
' The delegate which we will call from the thread to update the form<br />
Private Delegate Sub UpdateProgessCallback(ByVal BytesRead As Int64, ByVal TotalBytes As Int64)<br />
' When to pause<br />
Private goPause As Boolean = False<br />
Private Sub Download(ByVal startPoint As Object)<br />
Try<br />
<br />
Dim startPointInt As Integer = Convert.ToInt32(startPoint)<br />
' Create a request to the file we are downloading<br />
webRequest = DirectCast(Net.WebRequest.Create("http://dl.google.com/picasa/picasaweb-current-setup.exe"), HttpWebRequest)<br />
' Set the starting point of the request<br />
webRequest.AddRange(startPointInt)<br />
<br />
' Set default authentication for retrieving the file<br />
webRequest.Credentials = CredentialCache.DefaultCredentials<br />
' Retrieve the response from the server<br />
webResponse = DirectCast(webRequest.GetResponse(), HttpWebResponse)<br />
' Ask the server for the file size and store it<br />
Dim fileSize As Int64 = webResponse.ContentLength<br />
<br />
' Open the URL for download <br />
strResponse = webResponse.GetResponseStream()<br />
<br />
' Create a new file stream where we will be saving the data (local drive)<br />
If startPointInt = 0 Then<br />
strLocal = New FileStream("C:\", FileMode.Create, FileAccess.Write, FileShare.None)<br />
Else<br />
strLocal = New FileStream("C:\", FileMode.Append, FileAccess.Write, FileShare.None)<br />
End If<br />
<br />
' It will store the current number of bytes we retrieved from the server<br />
Dim bytesSize As Integer = 0<br />
' A buffer for storing and writing the data retrieved from the server<br />
Dim downBuffer As Byte() = New Byte(2047) {}<br />
<br />
' Loop through the buffer until the buffer is empty<br />
While (bytesSize = strResponse.Read(downBuffer, 0, downBuffer.Length)) > 0<br />
' Write the data from the buffer to the local hard drive<br />
strLocal.Write(downBuffer, 0, bytesSize)<br />
' Invoke the method that updates the form's label and progress bar<br />
' Me.Invoke(New UpdateProgessCallback(Me.UpdateProgress), New Object() {strLocal.Length, fileSize + startPointInt})<br />
<br />
If goPause = True Then<br />
Exit While<br />
End If<br />
End While<br />
Finally<br />
' When the above code has ended, close the streams<br />
strResponse.Close()<br />
strLocal.Close()<br />
End Try<br />
End Sub<br />
<br />
<br />
<br />
End Class<br />
Any suggestions will be thankful.
Dan.
|
|
|
|
|
Unlike C#, VB.NET doesn't allow variable assignment within a While loop header. You should modify your code to take account of this language difference.
Paul Marfleet
|
|
|
|
|
First, please use the <pre> tags when posting large snippets of code. It helps keep the formatting and makes it much easier to read.
Secondly, why are you converting the code? If the original project was written properly, you should be able to include the C# project in your solution or compile it separately and include the reference in your VB project to the DLL.
There are already several file downloader components here on CP that I know will work with VB code in the manner I describe above. You can check out this one[^] as a start.
|
|
|
|
|
Scott Dorman wrote: First, please use the "pre" tags when posting large snippets of code. It helps keep the formatting and makes it much easier to read.
Sorry , I was my mistake .:->
You suggested the perfect suggestion. Thanks.
|
|
|
|
|
Dan`M wrote: Sorry , I was my mistake
No problem. Just wanted to let you know for the future.
Dan`M wrote: You suggested the perfect suggestion. Thanks.
You're welcome.
|
|
|
|
|
Hi.I'm David Dlaka.
The Problem
Im making a projet with text files.There is a textbox in which you type some text.There are 3 buttons.Save,Open and Close.I'm having problem with the Save function.When you click save,an inputbox pops out and you need to type a code in it,so your files are secured.In the programming code the saving code is defined as "Short" ,but when i save it says:"Cast from string "mycode" to type 'Short' is not valid".Even if i change short with long,string integer or similar,it says tthe same thing!What do i do?
The code
This is the whole code
PrivateSub mnuSaveAsItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)Handles mnuSaveAsItem.Click<br />
Dim letter As Char Dim lngCode As Short <br />
Dim i, charsInFile As Long <br />
Dim Code As Short <br />
SaveFileDialog1.Filter = "Text files (*.txt)|*.txt"<br />
SaveFileDialog1.ShowDialog()<br />
If SaveFileDialog1.FileName <> "" Then <br />
lngCode = InputBox("Insert code to code the file.")<br />
If lngCode = "" Then Exit Sub <br />
Code = charsInFile = Txtnote.Text.Length<br />
FileOpen(1, SaveFileDialog1.FileName, OpenMode.Output)<br />
letter = Txtnote.Text.Substring(i, 1)<br />
Print(1, Asc(letter) <br />
CShort(lngCode)For i = 0 To charsInFile - 1Xor Code)Next <br />
FileClose(1)<br />
mnuCloseItem.Enabled = True End If End Sub Private Sub mnuCloseItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuCloseItem.ClickDim a As String <br />
a = InputBox("Did you save?")<br />
If a = ("Yes") Or a = ("yes") Then <br />
Txtnote.Text = ""<br />
ElseIf a = ("No") Or a = ("no") Then <br />
MsgBox("Don't forget to save your file first")<br />
Else <br />
MsgBox("Please answer with ""Yes"" or ""No""")<br />
End If <br />
End Sub <br />
Private Sub mnuOpenItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuOpenItem.ClickDim CelTekst, LinijaNaTekst As String Dim lngCode As Short <br />
OpenFileDialog1.Filter = "Text files (*.TXT)|*.TXT"<br />
OpenFileDialog1.ShowDialog()<br />
Dim Code As Short If OpenFileDialog1.FileName <> "" Then Try <br />
FileOpen(1, OpenFileDialog1.FileName, OpenMode.Input)<br />
LinijaNaTekst = LineInput(1)<br />
CelTekst = CelTekst & LinijaNaTekst & vbCrLf<br />
Do Until EOF(1)Loop <br />
Txtnote.Text = CelTekst<br />
Txtnote.Select(1, 0)<br />
Txtnote.Enabled = True <br />
mnuCloseItem.Enabled = True Catch <br />
MsgBox("Error with opening the file.")<br />
Finally <br />
FileClose(1)<br />
End Try <br />
End If <br />
End Sub Plese tell me what is wrong???
David Dlaka
|
|
|
|
|
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, ...
|
|
|
|
|