|
The following is the way to put the button and also add the functions for ConnectButton and DisconnectButton when those buttons are pressed.
however, whenever press one of button two functions will be executed instead of only the one with pressed but both of them. Why is that?
Dim WithEvents ConnectButton As CommandBarButton
Dim WithEvents DisconnectButton As CommandBarButton
' Connection Button
With ConnectButton
.Style = msoButtonIconAndCaption
.Caption = "Connect"
.FaceId = 19
.ToolTipText = "Press me for fun and profit."
'.OnAction = "ConnectButton"
.Tag = "My Big Button"
End With
'Disconnection Button
Set DisconnectButton = _
.Add(msoControlButton)
' Disconnect Button
With cbcDisconnectButton
.Style = msoButtonIconAndCaption
.Caption = "disconnect"
.FaceId = 19
.ToolTipText = "disconnect from iims"
'.OnAction = "DisconnectButton"
.Tag = "My Big Button"
End With
|
|
|
|
|
You're supplying the wrong code. What you should be looking at is the tail end of the Click handler functions for each button. Does they say something like this:
Private Sub ConnectButton_Click( ... ) Handles ConnectButton.Click, DisconnectButton.Click
What you problem is is two functions are handling the Click event for one button. Make sure that you don't see two event tags, or the wrong event tags at the end of the function declaration.
RageInTheMachine9532
|
|
|
|
|
>You're supplying the wrong code. What you should be looking at is the tail >end of the Click handler functions for each button. Does they say something >like this:
thanks i didn't have anything at the back of function name just
Private Sub ConectButton_Click()
{
..
}
so that's why, right. I only need to do is to put this handles statement
in order to get it work for each event.
Thanks for your help.
Shiny
|
|
|
|
|
With a ComboBox, I can write ComboBox1.DroppedDown = true.
How can I do the same with DateTimePicker?
Thank you,
Dino
Dino Buljubasic
|
|
|
|
|
With a ComboBox, I can write ComboBox1.DropDown = true.
How can I do the same with DateTimePicker?
Thank you,
Dino
Dino Buljubasic
|
|
|
|
|
Hi, I'm having the same problem. Did you solve this?
/=/=/=/= Sagmam =\=\=\=\
|
|
|
|
|
|
Some time ago I developed a custom control in a Class Library project. It has worked flawlessly, but over the weekend, as I was trying to deploy my application, It suddenly started giving problems. When ever I open the solution which references the custome control, I get a build error "Specified cast is not valid".
I can still build the application and it works fine, but the design view of the custome control won't open. I get the same error message on the [Design]tab. I also tried to close the form and reopen it. The same thing happens. I have tried removing the custome control and re-adding it (and the reference to it) to the solution, but that doesn't help. I'm not even sure whether the problem is in the custom control or in the project that reference it.
Help!
|
|
|
|
|
So yeah, I need some help. I want to create a sub that will allow me to select a source file, select a destination text (.txt) file, and write to that text file the code neccessary to programatically create the source file.
Why would I do such a ludicrously convoluted thing, you ask?
1) I need to create programs that automatically detect whether or not there is a certain file in the root folder, and if that file doesn't exist, I want it to create the file (i.e. a ReadMe file, usually an HTML file).
2) Since they are usually HTML files and I know squat about HTML, it would be easier just to create the file (using OpenOffice.Org in my case), and automate the arduous task of retrieving the HTML source.
3) I don't really have a third thing, but I felt three was the neccessary number of topics to address, and figured it'd be lame to stop at two.
Here's what I have so far:
Public Sub FileCopyCode()<br />
'Declaring variables<br />
Dim FileOpen As OpenFileDialog<br />
Dim SourcePath, OutPath As String<br />
Dim FileSave As SaveFileDialog<br />
Dim SourceFile As System.IO.File<br />
Dim SourceWrite As System.IO.StreamWriter<br />
'Starting the procedure<br />
FileOpen.ShowDialog()<br />
SourcePath = FileOpen.FileName<br />
FileSave.Filter = "Text File|txt"<br />
FileSave.ShowDialog()<br />
OutPath = FileSave.FileName<br />
SourceWrite = SourceFile.CreateText(OutPath)<br />
Dim SourceRead As System.IO.StreamReader<br />
SourceRead = SourceFile.OpenText(SourcePath)<br />
'Now, if I could just set up a loop starting here...<br />
'::Count number of lines in source file, loop following_<br />
'_procedure that many times::<br />
SourceWrite.WriteLine("FilePut(1, " & SourceRead.ReadLine)<br />
'...and ending about here, then maybe I could copy_<br />
'_each line with the FilePut thing in front, and boom! I'd have_<br />
'_what I want<br />
End Sub 'How to programatically create a text file containing the <br />
'_VB.Net code neccessary for recreating a different file programatically<br />
Any help is appreciated, thanks.
As I sit here, I contemplate the last words of Socrates: "I drank what?".
|
|
|
|
|
...
so u want to make a sub which will create a text file. this text file it creates must include the text (code) which is required to create a text file...?
doesnt seem hard, i can help you out. i just dont want to go do this and not be what is requested.
------------------------
Jordan.
III
|
|
|
|
|
Herm... let me try to explain it better:
Say, for example, you create a ReadMe file you plan to use with your program. The file is an HTML file, because you like to use funny formats and hyperlinks and whatnot. Anyway, you want your program, when started, to check the root folder and see if that file exists there. If it doesn't exist, you want your program to create that file. What would you do? You would code your program to check for the file and create it if it doesn't exist, simple as that.
Now, in the case of HTML files, you'd have to type the code to write the file line by line, as in the following example:
Public Sub CopyMake()
copyrightFile = Application.StartupPath & "\Copyright Info.htm"
If System.IO.File.Exists(copyrightFile) = False Then
FileOpen(1, copyrightFile, OpenMode.Binary)
FilePut(1, "<html>" & Environment.NewLine)
FilePut(1, Environment.NewLine)
FilePut(1, "<meta http-equiv='Content-Language' content='en-us'>" & Environment.NewLine)
FilePut(1, "<meta name='GENERATOR' content='Microsoft FrontPage 5.0'>" & Environment.NewLine)
FilePut(1, "<meta name='ProgId' content='FrontPage.Editor.Document'>" & Environment.NewLine)
FilePut(1, "<meta http-equiv='Content-Type' content='text/html; charset=windows-1252'>" & Environment.NewLine)
FilePut(1, "<title>Framework Download</title>" & Environment.NewLine)
FilePut(1, "</head>" & Environment.NewLine)
FilePut(1, Environment.NewLine)
FilePut(1, "<body>" & Environment.NewLine)
FilePut(1, Environment.NewLine)
FilePut(1, "<p>Coded by Mike</p>" & Environment.NewLine)
FilePut(1, "<p>Project started on Wednesday, March 24, 2004</p>" & Environment.NewLine)
FilePut(1, "<p>Email me at:</p>" & Environment.NewLine)
FilePut(1, "<a href='mailto:CodeMonkey85@hotmail.com'>" & Environment.NewLine)
FilePut(1, "codemonkey85@hotmail.com</a></p>" & Environment.NewLine)
FilePut(1, Environment.NewLine)
FilePut(1, "</body>" & Environment.NewLine)
FilePut(1, Environment.NewLine)
FilePut(1, "</html>" & Environment.NewLine)
FileClose(1)
End If
End Sub
As lazy as I am, I would hate to type all of that. So I thought to myself, "Self, you know how to programatically create simple text files, and how to read text from other files. You could easily program a routine to read from an HTML file like the one created above, and simply write the code required to create the file into a text file." And this is what I want to do.
I want my sub to read, for example, an HTML file. Since it only reads simple text, it would read the HTML source. Then, I want it to append whatever VB.Net code is required to programatically create the file (as in the example above), and write the result to a text file, which I can simply copy and paste into my new project. It should go something like this:
1. I run the sub, and it shows a file open dialog. I choose the source file (for example, an HTML file).
2. I pick a destination file path and file name (let's say I wanted it saved on my desktop) for the intended text file.
3. The sub reads the source file, writes the source to the destination text file and appends the VB.Net coding required to recreate the file in a different sub.
4. Now, if I open the text file, a sub that creates the source file I picked should be in there. I can copy and paste this into a project, and when I run that sub, it will recreate the file I picked at the beginning of the other sub.
I hope you all understand this now. I tried to be specific and all.
As I sit here, I contemplate the last words of Socrates: "I drank what?".
|
|
|
|
|
wow. i must be an idiot. still lost.
ok, the sub will:
1 - select file to read (html file)
2 - select file to save output to (txt)
3 - take the txt in the html (input) file and saves it to the txt (output) file, including the actual vb code required to do this.
ok for demonstration purposes:
myHomePage.html:
----------------------------------------------------------------------------------------------
<html>
<title>Heres my title</title>
<body>
<p>here is all my text for the web page.</p>
</body>
</html>
----------------------------------------------------------------------------------------------
myDoc.txt (after program executed):
----------------------------------------------------------------------------------------------
Private Sub MakeFile()
Dim inFile As StreamReader = File.OpenText(Application.StartupPath & "\myHomePage.html")
Dim outFile As StreamWriter = File.CreateText(Application.StartupPath & "\myDoc.txt")
outFile.Writeline("<html>")
outFile.Writeline("<title>Heres my title</title>")
outFile.Writeline("<body>")
outFile.Writeline("<p>here is all my text for the web page.</p>")
outFile.Writeline("</body>")
outFile.Writeline("</html>")
outFile.Close()
inFile.Close()
End Sub
----------------------------------------------------------------------------------------------
is this somewhat on the right track?
------------------------
Jordan.
III
|
|
|
|
|
Err, not quite. First of all, I don't want to have to hardcode the source into the program, or else 1) what would be the point in selecting the source file, and 2) it would have to be modified and recompiled each time I wanted to copy a file.
I want a sub that would take your example HTML file, and create a text file containing this:
Private Sub MakeFile()
Dim inFile As StreamReader = File.OpenText(Application.StartupPath & "\myHomePage.html")
Dim outFile As StreamWriter = File.CreateText(Application.StartupPath & "\myDoc.txt")
outFile.Writeline("<html>")
outFile.Writeline("<title>Heres my title</title>")
outFile.Writeline("<body>")
outFile.Writeline("<p>here is all my text for the web page.</p>")
outFile.Writeline("</body>")
outFile.Writeline("</html>")
outFile.Close()
inFile.Close()
End Sub
This would be a text file containing the VB.Net code required to remake the source file, which is what I want the original sub to make. In other words, if I were to run this code on a program (that is to say, the code in the new text file), it would create the myHomePage.html file in the bin folder.
As I sit here, I contemplate the last words of Socrates: "I drank what?".
|
|
|
|
|
didnt u just repeat me?
in your last post u copied and pasted my example for the txt document output, and said that that is what you want it to show... well thats exactly wut i was asking. i pasted that code there as an example of what the output for the txt file is that you are looking for, is that exactly what you are looking for? im working on it right now, post in afew minutes.
------------------------
Jordan.
III
|
|
|
|
|
ok.. is this more accurate:
ACTUAL CODE FOR SUB:
-------------------------------------------------------------------------------------------------------
Private Sub MakeFile(ByVal source As String, ByVal destination As String)
Dim inFile As StreamReader = File.OpenText(source)
Dim outFile As StreamWriter = File.CreateText(destination)
outfile.WriteLine("Private Sub MakeFile(ByVal source As String, ByVal destination As String)")
outfile.WriteLine("Dim inFile As StreamReader = File.OpenText(source)")
outFile.WriteLine("Dim outFile As StreamWriter = File.CreateText(destination)")
outFile.WriteLine()
Do Until inFile.Peek = -1
outFile.WriteLine("outFile.WriteLine(" & Chr(34) & inFile.ReadLine & Chr(34) & ")")
Loop
outFile.WriteLine()
outFile.WriteLine("outFile.Close()")
outFile.WriteLine("inFile.Close()")
outFile.WriteLine()
outFile.WriteLine("End Sub")
outFile.Close()
inFile.Close()
End Sub
-------------------------------------------------------------------------------------------------------
CONTENTS OF .txt FILE AFTER PROGRAM EXECUTED:
-------------------------------------------------------------------------------------------------------
Private Sub MakeFile(ByVal source As String, ByVal destination As String)
Dim inFile As StreamReader = File.OpenText(source)
Dim outFile As StreamWriter = File.CreateText(destination)
outFile.WriteLine("<html>")
outFile.WriteLine("<title>Heres my title</title>")
outFile.WriteLine("<body>")
outFile.WriteLine("<p>here is all my text for the web page.</p>")
outFile.WriteLine("</body>")
outFile.WriteLine("</html>")
outFile.Close()
inFile.Close()
End Sub
-------------------------------------------------------------------------------------------------------
for the .txt file part above (the outfile.writeline("<html>")) part), is that correct? or should it display the Do/Loop as shown at the top (in the actual sub's code), in place of all the 'outFile.WriteLine' commands with the html tags
------------------------
Jordan.
III
|
|
|
|
|
Yayness! It works! Unfortunately, when I try to copy certain files, quotation marks tend to get in the way... but for my purposes this will do just fine. Thanks for the help!
As I sit here, I contemplate the last words of Socrates: "I drank what?".
|
|
|
|
|
is that wut u were looking for? or did u solve it? if so, post your method.
i got around the quotation mark problem by using Chr(34) so there shouldnt b a problem.
------------------------
Jordan.
III
|
|
|
|
|
Ummm...why not just keep another copy of the files somewhere? Then write an app that can compare the last modified times of the working copies to the stored copies and if they are different, copy the stored copy back out to the working copy?
RageInTheMachine9532
|
|
|
|
|
Well, I was trying to keep my program as stand alone as possible, so keeping another copy of the files would be good, but I'd rather do it the dumb way.
I'll have to try Chr(34) soon. Other than that, this is exactly what I wanted.
As I sit here, I contemplate the last words of Socrates: "I drank what?".
|
|
|
|
|
i used the Chr(34) in the example i provided.
simply copy and paste the exact sub from my example afew posts ago, and test it out.
------------------------
Jordan.
III
|
|
|
|
|
The only problem I have is when I get lines like this in the output text file sub:
outFile.WriteLine("")
Naturally, the issue is with the quotation marks. If I could get that to look like this instead:
outFile.WriteLine("")
Then I wouldn't get any problems. Bear in mind that this is the product of your exact sub. In any case, it doesn't really matter, because the sub accomplishes exactly what I need it to; it gives me the code to copy smaller, more simple HTML files. Therefore, I don't think this will be an issue.
I hope not. Anyway, thanks again for your help.
As I sit here, I contemplate the last words of Socrates: "I drank what?".
|
|
|
|
|
Does anyone know how to save entries from a form to a file so they can be accessed for later viewing? I need to be able to pull the saved data back to the form it was saved from for later use. If anyone could help me with this I'd appreciate it.
Thanks,
ccotton333
|
|
|
|
|
If you are using a Windows Form, you could bind your "entries" (textboxes and other controls, I suppose) to a DataSet, and then use the WriteXML() and ReadXML() DataSet methods to serialize/deserialize it on a disk file.
|
|
|
|
|
I would just save toa text file. Then you could read from the file to restore the valus. It is easy. You need System.io an duse stream reader and stream writer.
I have a logon form which is check for a saved user name from a file at load. And on Enter I save the user name to this same file. That way the user name is remembered when the program is ended and then restarted.
Ex. ( sName4User is global variable,
Private Sub frmLogon_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' This will retreive a user name from file if present.
' Opens a file stream for reading
Dim myFS As New FileStream("c:\winnt\Temp\User.txt", FileMode.OpenOrCreate, FileAccess.Read, FileShare.None)
Dim myReader As New StreamReader(myFS) ' Assigning a reader
sName4User = myReader.ReadLine 'Retreives username
If Not sName4User Is Nothing Then
txtName.Text = sName4User
End If
myReader.Close()
End Sub
Private Sub btnEnter_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEnter.Click
'Storing username to file and closing if a username was entered
If txtName.Text <> "" Then
sName4User = txtName.Text
' Opens a file stream for reading
Dim myFS As New FileStream("C:\winnt\Temp\User.txt", FileMode.OpenOrCreate)
Dim myWriter As New StreamWriter(myFS) ' Assinging a reader
myWriter.WriteLine(sName4User) ' Storing to the file
myWriter.Close()
Me.DialogResult = DialogResult.OK
Else
txtName.Text = "Enter a user name"
txtName.Focus()
txtName.SelectAll()
End If
End Sub
|
|
|
|
|
I want a simple socket programming application in vb.net. Can any one of them help me out.
|
|
|
|
|