|
I would appreciate it if some one could help me. I don't know how to write the code to save or save as in my forms. Here is the code that I have so far. Note that my parent form has file(new,open, save, save as, close) on it. I have already done the new code and I have been searching through the help files of .Net for 2 hours now with no help what so ever. Also please note that opion strict is set to on.
Public Class frmMDI
Inherits System.Windows.Forms.Form
Dim counter As Integer = 1
Private Sub frmMDI_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Dim j As Integer
'For j = 1 To 3
' Dim frmDocForm As New frmChild
' frmDocForm.MdiParent = Me
' frmDocForm.Show()
'Next
End Sub
Private Sub ToolBar1_ButtonClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ToolBarButtonClickEventArgs) Handles ToolBar1.ButtonClick
If e.Button.Tag Is "new" Then
NewFile()
ElseIf e.Button.Tag Is "open" Then
ElseIf e.Button.Tag Is "save" Then
ElseIf e.Button.Tag Is "bold" Then
Dim frmActiveChild As frmChild = Me.ActiveMdiChild
If (Not frmActiveChild Is Nothing) Then
'process the child form – save, close, whatever
frmActiveChild.txtDoc.Font = New Font(Me.Font, FontStyle.Bold)
End If
End If
End Sub
#Region "Menu Code"
#Region "Window Code"
Private Sub mnuCascade_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuCascade.Click
Me.LayoutMdi(MdiLayout.Cascade)
End Sub
Private Sub mnuHorizontal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuHorizontal.Click
Me.LayoutMdi(MdiLayout.TileHorizontal)
End Sub
Private Sub mnuVertical_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuVertical.Click
Me.LayoutMdi(MdiLayout.TileVertical)
End Sub
#End Region
#Region "File Code"
Private Sub mnuNew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuNew.Click
NewFile()
End Sub
Private Sub mnuOpen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuOpen.Click
End Sub
<b> Private Sub mnuSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuSave.Click
End Sub
Private Sub mnuSaveAs_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuSaveAs.Click
End Sub</b>
Private Sub MenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem1.Click
End Sub
#End Region
#End Region
#Region "Procedures"
Private Sub NewFile()
Dim frmDocForm As New frmChild
frmDocForm.MdiParent = Me
frmDocForm.isDirty = False
frmDocForm.newDoc = True
frmDocForm.docName = "Document" & CStr(counter)
counter += 1
frmDocForm.Text = frmDocForm.docName
frmDocForm.Show()
End Sub
#End Region
this is the code in my child form.
Public Class frmChild
Inherits System.Windows.Forms.Form
'---------------------------------------------------
'Public attributes (instance variables)
'isDirty: Set True if document needs to be saved
Public isDirty As Boolean
'newDoc: Set True if form was just created using New
'(no file on disk yet)
Public newDoc As Boolean
'docName: Set to filename of document (no path info)
Public docName As String
'pathName: Set to path (directory) where file saved
'(does not include filename)
Public pathName As String
End Class
|
|
|
|
|
if all you need is to write to a file, simply use the FileStream object in the frameworks
(if it is then the title of your message is VERY misleading, if not, then my reply is useless )
the basics are to create a FileStream object reference
Dim MyFileStream as System.IO.FileStream
and then you need to create the file stream, by opening the file
if it is a new file (there isn't a file with the same name at the same directory)
you should create the file like so:
MyFileStream = IO.File.Open(MyFilePath, IO.FileMode.CreateNew)
if the file already exists, you would probably want to erase the data and rewrite it do:
FileStream = SystemIO.File.Open(MyFilePath, IO.FileMode.Truncate)
to check whether the file exists use:
If System.IO.File.Exists(MyFilePath) Then ...
if you want to be really smart about it, you can scan the file to see what segements of have been chaged and only write those parts (mostly usefull in large files)
Fade (Amit BS)
|
|
|
|
|
Does anybody know how to get the ‘X’ click event?….the ‘X’ in the upper right hand corner of a form.
I want to perform a function if the ‘X’ is used to close the form (something like frmMain_ClickX) but if I use frmMain_Closing it causes certain functions to execute twice.
I’m assuming that frmMain_Click is not specifically associated with the click event of the ‘X’.
Thanks
Brad
|
|
|
|
|
Private Sub whatever_you_want(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
|
|
|
|
|
I’m still a bit confused.
I have the following sub that I want to be sure is executed whenever the form closes:
SaveData()
I have programmed the sub ‘SaveData()’ to execute under the ‘mnuExit_Click’ (and other areas).
My problem is that ‘SaveData()’ is executed once when ‘mnuExit_Click’ is executed and then again during frm1_cloising.
I assume that it is bad practice to just execute ‘SaveData()’ in ‘frm1_closing’ and in no other location.
Thanks
Brad
|
|
|
|
|
Brad Fackrell wrote:
I assume that it is bad practice to just execute ‘SaveData()’ in ‘frm1_closing’ and in no other location.
The reason why it's getting executed twice is because you execute it in the mnuExit handler AND your doing it again when the Closing event is fired. If you want to handle all possible ways of closing a form, then the Closing event is the way to go...
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Dave Kreskowiak wrote:
If you want to handle all possible ways of closing a form, then the Closing event is the way to go...
Okay. I thought that would work but then I "second guessed" myself because I thought; Why add any sub routines under mneExit?
Thanks Dave.
|
|
|
|
|
Replace SaveData() in mnuExit_Click and all other locations (except frm1_closing) by Me.Close().
|
|
|
|
|
Works perfect! Thank you
Brad
|
|
|
|
|
Hi, I am having a problem with the drop down mode in a combo box. I have set up a combo box that allows the user to type values and the list will filter out and select the next closest item. It is a multicolumn, autocomplete combobox. The value member, text, and other properties can be found when the item exists in the list, but when the user types a value not found within the list, I get index 0 problems. I was wondering if anyone has any suggestions on how I can fix or get around this problem. Thank you.
|
|
|
|
|
I am rewriting a VBA excel funtion that has ranges in VB.NET
I have no clue how to do the ranges in vb.net (most likely a 2 D array).
The following is the VBA excel function that I am trying to rewrite.
strip(Today,EndDate1Yr,$L$120:$L$122,$A$20:$B$23,$E$4:$F$9)
today = startdate (date datatype)
enddate1yr = fordate (date datatype)
intraday = range
serial = range
standard = range
Does any one suggest me or share any code pointers that can help me to proceed.
thanks
nath
|
|
|
|
|
I'm trying to parse a text file using the .readline() method of streamreader. My problem is that my code (below) won't work with text files that have blank lines. It thinks this is an 'end of the file' statement. Is there something else i can test in the conditional statement besides "Do until strLine = Nothing" so that i can read even a blank line and read the file straight through to the 'real' end of file?
---------------------------
strLine = srdCurrent.ReadLine()
Do Until strLine = Nothing
strFile += strLine & CrLf
strLine = srdCurrent.ReadLine()
Loop
----------------------------
|
|
|
|
|
Try this example, it reads from a file (including blank lines) into a TextBox:
Dim file As New IO.StreamReader("c:\temp\test.txt")
While file.Peek > 0
TextBox1.Text += file.ReadLine() & vbCrLf
End While
file.Close()
Hope this helps
Tom
|
|
|
|
|
Hey it worked! Thanks!
jaspe
|
|
|
|
|
i would do it differently, instead of peeking into the file (which is generally not a good thing to do due to various reasons)
use this statement instead
while MyStramReader.BaseStream.Position < MyStramReader.BaseStream.Length<br />
...
should also work faster (i think...)
Fade (Amit BS)
|
|
|
|
|
Good suggestion! I'll give it a try, thanks!
jaspe
|
|
|
|
|
Hi,
Is there a way to format each line of text in a rich text box to be a different font at design time
|
|
|
|
|
No. When you set up the font property, it applies to all lines in rich text box. There´s no way you can do that.
|
|
|
|
|
im a vb6 programmer and im shifting right now to vb.net..i just want to know the counter part of my routine of saving in vb6 to vb.net using adapter and dataset..this is a combination of addnew and update..it goes like this..im made it very basic just to give you the scenario..
--routine in vb6 saving--
dim cn as adodb.connection
dim rs as new adodb.recordset
dim xsql as string
cn.open connectionstring
xsql="select * from table where field='" & txt & "'"
rs.open xsql,cn,....
if rs.eof then
rs.addnew 'if no records found
rs!id=txtid
end if
rs!lastname=txtlastname
rs!firstname=txtfirstname
rs.update
pls help if anyone has the idea..
|
|
|
|
|
Are you going to set up the connection in code or use the appropriate dataadapter? If by using the adapter, you would setup the adapter with the database you want to connect to(i.e. if using Access then use Jet 4.0) then generate the dataset for that dataadapter. Most of the time I just bind my textboxes in the databinding section of the property box. then to adda the record would go something like this:
'this adds new record to the dataset
Try
dim newrow as datarow = dataset.Tablename.newrow
newrow("lastname")=txtlastname.text
newrow("firstname")=txtfirstname.text
dataset.tablename.rows.add(newrow)
Catch ex as exception
messagebox.show(ex.tostring)
end try
'this update database based on the dataset
try
dataadapter.update(dataset, "Tablename")
catch ex as exception
messagebox.show(ex.tostring)
end try
|
|
|
|
|
How do we print a master detail form in VBNet without using Crystal report?
Any example in VBNet 2002:rolleyes :?
|
|
|
|
|
|
Hi all
I've following problem, i have an array of computer name (in LAN and not in LAN), all i want is get the domain name of specific computer (if the computer is in domain). For example, i've found a computer named "COMP1" which have controlled by a domain controller and i want to display the domain name of COMP1 (COMP1 is not in my LAN and is a internet computer which i've found by scanning IP).
I mentioned to use a function like that
Function GetDomain(ByVal sCompName As String) As String
'Do something here and get the domain name of sCompName and return to user
End Function
Is it a possible way to do that by programming with VB6?
Anyhelp might be very helpful
Thank alots!
.::LDLP::.
|
|
|
|
|
I'm using DataGridTableStyle to change the datagrid properties, but if it's using stored procedure, then it won't work, is there anybody knows why?
here is my code, when I run it, the datagrid headerText and width didn't change..
Dim DGTableStyle As New DataGridTableStyle
Dim textCol As New DataGridTextBoxColumn
grdAddPlan.TableStyles.Clear()
DGTableStyle.MappingName = "dbo.p_JobPlan"
textCol.MappingName = "EntityID"
textCol.HeaderText = " "
textCol.Width = 2
DGTableStyle.GridColumnStyles.Add(textCol)
textCol = New DataGridTextBoxColumn
textCol.MappingName = "ID"
textCol.HeaderText = "Plan ID"
textCol.Width = 30
DGTableStyle.GridColumnStyles.Add(textCol)
grdAddPlan.TableStyles.Add(DGTableStyle)
Lisa
|
|
|
|
|
I have written this code at page load and creating a dataset :
Dim cnn As MySqlConnection
cnn = New MySqlConnection ("SERVER=newserver;username=root;password=;DATABASE=new")
cnn.open()
Dim sql As String
sql = "select BillId, VenderID from tblbillMaster"
Dim dA As New MySqlDataAdapter(sql, cnn)
Dim DS As New DataSet
dA.Fill(DS, "tblBillMaster")
And I have added a Blank crystal Report in my project.
And I have added to parameter fields names: BillId , name
if my tblbillMaster have 5 rows then how these all rows
will display in Crystal REport in these two fields.
SoftWare Engineer
|
|
|
|