Jump to content
Xtreme .Net Talk

dynamic_sysop

Leaders
  • Posts

    1044
  • Joined

  • Last visited

Everything posted by dynamic_sysop

  1. you could specify OpenOrCreate : Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim sFilePath As String = "C:\somefile.html" Dim sWriter As New IO.StreamWriter(New IO.FileStream(sFilePath, IO.FileMode.OpenOrCreate, IO.FileAccess.Write)) sWriter.Write("<font color=""blue"">Private Sub </font> NewHtmlFile()<br><font color=""DarkGreen"">'/// a new file you made and wrote to!</font><br><font color=""Blue"">End Sub</font>") sWriter.Close() Dim pr As Process = New Process() pr.Start("IEXPLORE", sFilePath) '/// test the html file to see it's ok. End Sub
  2. why not do something like this : Dim x As Integer = 0 '/// make an integer thats available to all sub ( so it will keep counting ) '////////////////////// Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click ContextMenu1.Show(Button1, New Drawing.Point(0, 15)) End Sub Private Sub ContextMenu1_Popup(ByVal sender As Object, ByVal e As System.EventArgs) Handles ContextMenu1.Popup If x <> 0 Then If MenuItem1.Text = "HELLO" Then MenuItem1.Text = "WORLD" End If If MenuItem2.Text = "GOODBYE" Then MenuItem2.Text = "CYA" End If End If x = 1 End Sub
  3. just incase you are creating them at runtime here's an example of how to deal with the checked states : Private WithEvents CB As CheckBox Private chk(3) As CheckBox ' /// below your "windows generated code area"^^^ Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click chk(1) = New CheckBox() chk(1).Location = New System.Drawing.Point(304, 30) chk(1).Visible = True MyBase.Controls.Add(chk(1)) AddHandler chk(1).Click, AddressOf CB_Click End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click If Not chk(1) Is Nothing Then If chk(1).Checked = True Then MessageBox.Show("it's checked!") Else MessageBox.Show("it's NOT checked!") End If End If End Sub Private Sub CB_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles CB.Click '/// handle all checkboxes created at runtime in 1 sub. End Sub
  4. are you creating these checkboxes at design time or adding them as new checkboxes at runtime?
  5. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click If CheckBox1.CheckState = CheckState.Checked Then '/// do stuff Else '/// do other stuff cuz it aint checked. End If End Sub like that you mean ?
  6. StringBuilder is a great thing and you can use many Win32 api's with it ( which will return blank with normal strings )
  7. try this , you need more than that code to record / save a wav . Private Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" (ByVal lpstrCommand As String, ByVal lpstrReturnString As String, ByVal uReturnLength As Integer, ByVal hwndCallback As Integer) As Integer '/// use Integer's not Longs Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim strVariable As String() = {"open new type waveaudio alias capture", "set capture bitspersample 8" _ & "set capture samplespersec 11025", "record capture"} mciSendString(strVariable(0), vbNullString, 0, 0) '/// create a new wav. mciSendString(strVariable(1), 0, 0, 0) '///set the bitrate. mciSendString(strVariable(2), 0, 0, 0) '///samples per second. mciSendString(strVariable(3), 0, 0, 0) '///lets record. End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click mciSendString("stop capture", 0, 0, 0) '/// stop recording. mciSendString("save capture c:\test.wav", 0, 0, 0) '/// save our new Wav. End Sub
  8. you could bung it in a module Imports System.Data Module Module1 Public Function OpenAccess(ByVal strFile As String, ByVal strCommand As String, ByVal strTable As String, ByVal DG As DataGrid) Dim objAccess As New OleDb.OleDbConnection(strFile) Try Dim objCmd As New OleDb.OleDbCommand(strCommand, objAccess) Dim objAdapt As New OleDb.OleDbDataAdapter(objCmd) Dim objSet As New Data.DataSet() objAdapt.Fill(objSet, strTable) DG.DataSource = objSet.Tables(strTable) Catch ex As Exception MessageBox.Show(ex.Message) Finally objAccess.Close() End Try End Function End Module then in a form / all the forms required : Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim constring As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\MyDb.mdb" Dim command As String = "SELECT * FROM Table1" OpenAccess(constring, command, "Table1", DataGrid1) End Sub
  9. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim x As Integer For x = 0 To Me.TabControl1.TabCount - 1 Me.TabControl1.TabPages(x).ImageIndex = x '/// assuming you have 6 images in an imagelist. Next End Sub
  10. lol just as i make an example : Private WithEvents nIcon As NotifyIcon Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click nIcon = New NotifyIcon() nIcon.Icon = Me.Icon nIcon.Visible = True Me.ShowInTaskbar = False End Sub Private Sub Form1_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing If Not nIcon Is Nothing Then nIcon.Icon = Nothing nIcon.Visible = False nIcon = Nothing End If End Sub Private Sub nIcon_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles nIcon.DoubleClick MessageBox.Show("i'm how you get in the area where the clock is!") Me.Close() End Sub
  11. also you can convert html colors etc ... Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim c As ColorTranslator Dim i As Color = c.FromHtml("#ff400000") Me.BackColor = i End Sub
  12. here's way 1 ( the value you get is the Integer value of the ffxxxx ) Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Me.BackColor = Color.FromArgb(-12345902) End Sub
  13. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim dr As Directory If dr.Exists("C:\fakeDir") Then MessageBox.Show("it exsists!") Else MessageBox.Show("it doesn't exsist are you sure you put the correct directory name?") End If End Sub :)
  14. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click MessageBox.Show("1,2345".Split(",")(1)) End Sub :)
  15. you could do this : Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim i As Integer = 5 Dim x As Integer For x = 1 To 5 TextBox1.Text = i i = i - 1 Application.DoEvents() Threading.Thread.Sleep(1000) Next End Sub or better still as Divil says use a timer , eg : Dim x As Integer = 5 ' /// made available to all subs ^^^ ' /// Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Dim i As Integer TextBox1.Text = x For i = 1 To 4 With Timer1 .Interval = 1000 .Enabled = True .Start() End With Next End Sub Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick TextBox1.Text = x x = x - 1 If x < 1 Then Timer1.Stop() x = 5 End If End Sub
  16. you dont need quite so many Try / Catches in there , here's a simple example that has less lines of code and works without a problem : Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Dim sReader As StreamReader Try sReader = New StreamReader(New FileStream("C:\test.txt", FileMode.Open, FileAccess.Read)) While Not sReader.Peek MessageBox.Show(sReader.ReadLine) End While Catch ex As Exception MessageBox.Show(ex.Message) Finally sReader.DiscardBufferedData() sReader.Close() sReader = Nothing End Try End Sub
  17. try looking at this thread... ( directly below yours ) i put a sample code there . open an access database ( with / without password )
  18. it gives that message when the connection string isn't correct ( especially if using a password ) here's a quick example ( without password in connection string ) Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click Dim constring As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\MyDb.mdb" Dim objDbConnection As New OleDbConnection(constring) Try objDbConnection.Open() Dim objCommand As New OleDbCommand("SELECT * FROM Table1", objDbConnection) Dim objAdaptor As OleDbDataAdapter = New OleDbDataAdapter(objCommand) Dim objDataSet As New DataSet() objAdaptor.Fill(objDataSet, "Table1") DataGrid1.DataSource = objDataSet.Tables("Table1") Catch ex As Exception MessageBox.Show(ex.Message) Finally objDbConnection.Close() End Try End Sub if you choose to use a pwd protected database you can do this : Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim strPath As String = Application.StartupPath & "\db4.mdb" Dim strPass As String = "sysop" '/// the password for your db goes here. Dim Connection As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strPath & ";Jet OLEDB:Database Password=" & strPass & ";User ID=Admin;Persist Security Info=True" Dim Command As String = "SELECT * FROM Table1" OpenAccessFile(Connection, Command) End Sub Private Sub OpenAccessFile(ByVal strConnection As String, ByVal strCommand As String) Try Dim objDbConnection As New OleDbConnection(strConnection) objDbConnection.Open() '///open a new connection. Dim objCommand As New OleDbCommand(strCommand, objDbConnection) Dim objAdaptor As OleDbDataAdapter objAdaptor = New OleDbDataAdapter(objCommand) Dim objDataSet As New DataSet() objAdaptor.Fill(objDataSet, "Table1") DataGrid1.DataSource = objDataSet.Tables("Table1") '///fill a datagrid with the recordset objDbConnection.Close() objCommand.Dispose() objAdaptor.Dispose() objDataSet.Dispose() Catch ex As Exception MessageBox.Show(ex.Message) End Try End Sub hope it helps ( but dont go un-installing access , it's not that drastic )
  19. you want to do this i guess? : Private WithEvents TextBox As TextBox Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load AddHandler TextBox1.Validating, AddressOf TextBox_Validating AddHandler TextBox2.Validating, AddressOf TextBox_Validating End Sub Private Sub TextBox_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles TextBox.Validating Try If sender.text = "" Then e.Cancel = True Dim x As Exception = New Exception("oops " & sender.name & " doesnt have any text in it!") Throw x End If Catch ex As Exception MessageBox.Show(ex.Message) End Try End Sub both textboxes get handled properly by 1 sub and the message tells the user which box is empty.
  20. here ya go , took me a while of messing but i sussed it :) Private Const VK_UP As Integer = CInt(&H26) Private Const VK_RIGHT As Integer = CInt(&H27) Private Const VK_LEFT As Integer = CInt(&H25) Private Const VK_DOWN As Integer = CInt(&H28) Protected Overrides Function ProcessKeyPreview(ByRef m As System.Windows.Forms.Message) As Boolean Select Case m.WParam.ToInt32 Case VK_UP MsgBox("up") Case VK_DOWN MsgBox("down") Case VK_LEFT MsgBox("left") Case VK_RIGHT MsgBox("right") End Select End Function
  21. using a reference to the microsoft excel object library ( 10.0 in this case ) Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim oDialog As New OpenFileDialog() oDialog.Filter = "Excel files|*.xls" '/// select an excel file from an opendialog box. oDialog.ShowDialog() Dim objExcel As New excel.Application() Dim objBook As excel.Workbook = objExcel.Workbooks.Open(oDialog.FileName) Dim objSheet As excel.Worksheet = objBook.Worksheets.Item("Sheet1") '/// your sheet name here. Dim x As Integer Try For x = 1 To objSheet.UsedRange.Count ListBox1.Items.Add(objSheet.UsedRange(x).value) '/// add each item from Sheet1 to a listbox. Next objSheet.Cells(1, x).value = "a new item added" '/// add a new item to the next free column in row 1. objBook.Save() '/// save the changes. Catch ex As Exception MessageBox.Show(ex.Message) Finally objExcel.Application.Quit() objSheet = Nothing objBook = Nothing objExcel = Nothing End Try End Sub
  22. not sure if this helps : Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click Dim str() As String = "CA3*450*325*225*0*775*650*350*425".Split("*") Dim fakeTextBox() As String = DirectCast(str, Array) Dim i As Integer, x As Integer, tb As Control For i = 1 To 8 x = i - 1 For Each tb In Me.Controls If TypeOf tb Is TextBox Then If tb.Name = "TextBox" & i Then tb.Text = fakeTextBox(x) End If End If Next Next End Sub
  23. in english it's : roughly i think ;) not sure if this is what you want to know : Private Sub Splitter1_SplitterMoving(ByVal sender As Object, ByVal e As System.Windows.Forms.SplitterEventArgs) Handles Splitter1.SplitterMoving Me.Text = e.X '/// current position of the splitter's bar End Sub in itallian :
  24. here's how i'd handle the event , you can add more handlers as you go along : Dim obj As MenuItem Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click obj = MenuItem1.MenuItems.Add("some text") AddHandler obj.Click, AddressOf item1_Click End Sub Public Sub item1_Click(ByVal sender As Object, ByVal e As System.EventArgs) MsgBox(sender.text) End Sub hope it helps.
  25. if you want to ensure that Load1 gets loaded before Load2 you can do this : Private Sub Dossier_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load Load1() Application.DoEvents() Load2() Application.DoEvents() End Sub if you only want to ensure that before leaving the Dossier_Load sub , it's loaded both , you could do this : Private Sub Dossier_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load Load1() Load2() Application.DoEvents() End Sub
×
×
  • Create New...