Jump to content
Xtreme .Net Talk

a_jam_sandwich

Avatar/Signature
  • Posts

    371
  • Joined

  • Last visited

Everything posted by a_jam_sandwich

  1. sorry please read the readme.txt file that comes with it but all ip\url directory etc is in the .ini file
  2. quite true use the timer control so on each tick it checks Andy
  3. I did a program that connected to a HTTP and downloaded files This is the link http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=936&lngWId=10 Shouldn't be 2 hard to convert it to FTP instead of HTTP Andy
  4. if I was you i'd have a time out of perhaps 30secs Andy
  5. In dot net the idea has been to move away from ActiveX controls look at the Socket name space What are you trying to do???? Andy
  6. Ill try and write another tutorial for Datasets and databinding 2nite should shed some light then Andy
  7. You could create a SQL file with all the updates in it Once this file is downloaded. Open and run through the file, running the SQL commands as you go Andy
  8. Check that out http://www.xtremedotnettalk.com/t69746.html
  9. cn.State will give you the current state of the connection e.g. if cn.state = ConnectionState.Open then 'Do Somthing End if
  10. I Don't belive the OLEdb provider supports ODBC connections to use the ODBC use the ODBCdb namespace which you will have to download additionally. see http://msdn.microsoft.com/downloads/default.asp?url=/downloads/sample.asp?url=/msdn-files/027/001/668/msdncompositedoc.xml Andy
  11. Here is a tutorial ive just written. Was supposed to be short a few lines well, never mind... Right what you need to do is first create a connection to the database, because you using Access you will use the OLEdb namespace. Your fistline(s) should be your imports so type Imports System.Data.OleDb This will enable us to access all the functions for the OLEdb namespace in shorthand. To access the Access database you will first need to create a connection to it via the OLEdb provider this can be done with the following code which creates a connection based of you connection string. Dim MyConnection As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\MYDB.mdb") MyConnection.Open Of course your Connection string will differ depending on your Database location, UID and password the above example only specifys the database location via the 'Data Source=' section. The second line opens the connection to the database so we can insert, update, delete and read from the database. Now depending on what you want to do with the database depends on the next set of commands. To read from the database you have 2 options the Datareader and the Dataadapter. Im not going into the Dataadapter here as for simple database applications you probley will not need it. The Dataadapter is an Forward only reader for returned database results. Anytime you wish to read, insert, update or delete information from the database you will need to ask the database before anything happens, this is an command. Command are just standard SQL (Standard Query Language) which enables you to do all the operations with the database as described above and guess what... Im not going into any detail about SQL either. the first example will be to get all the data from an Table called 'MyTable' in an database called 'MYDB.mdb' as shown above in the connection example. start of with the connection to the database as above Dim MyConnection As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\MYDB.mdb") MyConnection.Open Now create the command to get the Data from MyTable Dim MyCommand as New OleDbCommand("SELECT * FROM MyTable WHERE ID = 1", MyConnection) The above line does the following... Create a new command, The bit in the indices is the important stuff for fistoff Select all fields from the Table MyTable where the where we find a record in the table where its ID field is equal to 1. Now for the second bit the bit after the comma specifies to use the Connection 'MyConnection' as created in the previous lines. Right this is the Next line is needed so when we ask the database for Data (SQL) we can display through VB.NET Dim MyReader As OleDbDataReader = MyCOmmand.ExecuteReader() This is a very very important line as we are tell the command ('MyCOmmand') to execute and then put the returned data into the Reader 'MyReader'. This is line that in a second we will change so we can update, insert and delete instead of reading from the database the result will be only one record providing the database found the record from MyTable where ID = 1, in my case because i've put the record into database previously it exists and therefore returned. Now for the section we can see, displaying the returned result. All im going to show you is displaying the data in 3 Textboxes Lastname, Firstname and Address (Fields I have in mydatabase), this is done by the following code. While MyReader.Read Lastname.Text = MyReader("Lastname") Firstname.Text = MyReader("Firstname") Address.Text = MyReader("Address") End While All the above code does is first create an while loop and set the condition MyReader.Read all this means is loop though the reader until where at the end of the returned results. This happens when .Read = False. Each time we go though the loop through MyReader where are just advancing through the recordset, since we have only one Data result returned this will only go through the loop once. Notice MyReader("") this is the bit where we get the Field from the Reader and place it into the textbox the bit inbetween "" is the Fieldname. The last thing needed to do is to dispose \ Close all the objects as used above this is done by the following code. MyConnection.Close MyReader.Close MyCommand.Dispose The full code is below for displaying... Dim MyConnection As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\MYDB.mdb") MyConnection.Open Dim MyCommand as New OleDbCommand("SELECT * FROM MyTable WHERE ID = 1", MyConnection) Dim MyReader As OleDbDataReader = MyCOmmand.ExecuteReader() While MyReader.Read Lastname.Text = MyReader("Lastname") Firstname.Text = MyReader("Firstname") Address.Text = MyReader("Address") End While MyConnection.Close MyReader.Close MyCommand.Dispose Now for inserting. All the code is the same up until we create MyCommand. The Command will now hold the SQL for inserting a record. As above im just using 'Firstname', 'Lastname' and 'Address' I shold also point out that 'ID' as used in getting a record is a autonumber field in the database. Now for the SQL. INSERT INTO MyTABLE (firstname, Lastname, Address) VALUES ('Andrew', 'Duff', 'Not Telling') Thats it for the SQL, the first secion in the indices are the Fields I want to insert into and as in the SQL the second secion in indices are the values in inserting. Note... '' in the value list indicate that the values are Text if the values are numerical then '' would apply. right now we have the SQL the code looks like the follow to the point as above Dim MyConnection As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\MYDB.mdb") MyConnection.Open Dim MyCommand As New OleDbCommand("INSERT INTO MyTABLE (firstname, Lastname, Address) VALUES ('Andrew', 'Duff', 'Not Telling')", MyConnection) As when doing the Reader example we need to Run the command. To do this we only need one line of code which is. MyCommand.ExecuteNonQuery() This will now send the command to the Database to insert a record. now as above we need to dispose all the Objects MyConnection.Close MyReader.Close MyCommand.Dispose The code in Full for Inserting Dim MyConnection As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\MYDB.mdb") MyConnection.Open Dim MyCommand As New OleDbCommand("INSERT INTO MyTABLE (firstname, Lastname, Address) VALUES ('Andrew', 'Duff', 'Not Telling')", MyConnection) MyCommand.ExecuteNonQuery() MyConnection.Close MyReader.Close MyCommand.Dispose When Updating or Inserting only thing now needing to be changed is the SQL the syntax is the same as inserting Example SQL of Updating. UPDATE MyTable SET Firstname = 'Bobby' WHERE ID = 1 The above SQL will find the record where ID = 1 the same as in the Reading and change the Firstname from whatever it is to Bobby Full code as below. Dim MyConnection As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\MYDB.mdb") MyConnection.Open Dim MyCommand As New OleDbCommand("UPDATE MyTable SET Firstname = 'Bobby' WHERE ID = 1", MyConnection) MyCommand.ExecuteNonQuery() MyConnection.Close MyReader.Close MyCommand.Dispose Last one now fingers hurting Example SQL of Delete. DELETE FROM MyTable WHERE ID = 1 You've guessed remove the record where the ID = 1 from the Database. Full code as below. Dim MyConnection As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\MYDB.mdb") MyConnection.Open Dim MyCommand As New OleDbCommand("DELETE FROM MyTable WHERE ID = 1", MyConnection) MyCommand.ExecuteNonQuery() MyConnection.Close MyReader.Close MyCommand.Dispose I hope this helps if you need a example i'll knock one up Andy.
  12. Private Sub tbTemperture_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles tbTemperature.KeyPress If Not AscW(e.KeyChar) <= 47 And Not AscW(e.KeyChar) >= 58 _ Or AscW(e.KeyChar) = 8 Or AscW(e.KeyChar) = 46 Or Asc(e.KeyChar) = 45 Then If e.KeyChar = "." Then If TextBox1.Text.IndexOf(".") = -1 Then e.Handled = False Else e.Handled = True ElseIf e.KeyChar = "-" Then If TextBox1.Text.IndexOf("-") = -1 Then e.Handled = False Else e.Handled = True End If Else e.Handled = False End If End Sub Give that a try Andy
  13. There is an example within the microsoft examples of using the system tray. The control you want to look at is the NotifyIcon http://msdn.microsoft.com/vbasic/downloads/samples/default.asp is were you will find the examples
  14. use the printdocument contol there is an simple printing example in SDK
  15. The way i do the imputing in SQL is to specify the date as it DOUBLE number no confussion then :) Andy
  16. No its not flicker you can make it so no screen flick doesn't happen by the following code.... Dim itmX As ListViewItem ListView1.BeginUpdate() itmX = ListView1.Items(ListView1.Items.Count - 1) itmX.SubItems(9).Text = "BLUE" ListView1.Items(ListView1.Items.Count - 1) = itmX ListView1.EndUpdate() give that a go Andy
  17. Dim itmX As ListViewItem ' Get the last item into itmX itmX = ListView1.Items(ListView1.Items.Count - 1) ' Change column 10s text itmX.SubItems(9).Text = "My replaced text" ' Put back into listview as last item ListView1.Items(ListView1.Items.Count - 1) = itmX Hope this helps Andy
  18. Right, Im now trying to create a new control but I am very on confused on how to go around building it. The idea is to build a control that will hold a Collection of panels The general idea is that this control will replace the Tab Control in my application as I hate the look of those Tabs. In the end it will just be a page container. Anyone know any tutorials or information Cheers Andy
  19. Here we go a working version YIPPIE :p It can load multiple files into the class and then you can print preview them all in one go. Take a look Thanks to Martin Müller for the original C# code and Divil whos help is greatly appreciated . To view the original c# click here http://www.codeguru.com/cs_controls/RichTextEx.html
  20. FIXED IT WILL POST SOON Was the was I was referencing the user32.DLL
  21. Project so far for RTB printing in VB.NET Here is the project as it is so far anyone help ? Almost had enough of it Andy [edit] Removed binaries from attachment - divil [/edit] prtb.zip
  22. im getting closer Imports System Imports System.Drawing.Printing Imports System.Runtime.InteropServices Imports System.Windows.Forms Namespace RichTextExLib Public Class printRTF Inherits RichTextBox <StructLayout(LayoutKind.Sequential)> _ Private Structure RECT Public Left As Integer Public Top As Integer Public Right As Integer Public Bottom As Integer End Structure <StructLayout(LayoutKind.Sequential)> _ Private Structure CHARRANGE Public cpMin As Integer Public cpMax As Integer End Structure <StructLayout(LayoutKind.Sequential)> _ Private Structure sFORMATRANGE Public hdc As IntPtr Public hdcTarget As IntPtr Public rc As RECT Public rcPage As RECT Public chrg As CHARRANGE End Structure Private Declare Function SendMessage Lib "user32" Alias "SendMessage" (ByVal hwnd As IntPtr, ByVal wMsg As Integer, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr Private Const WM_USER As Integer = 1024 Private Const EM_FORMATRANGE As Integer = 1081 Private Const EM_SETTARGETDEVICE As Integer = 1096 Private Function HundredthInchToTwips(ByVal n As Integer) As Integer Return CInt(n * 14.4) End Function Public Function SetTargetDevice(ByVal g As Graphics, ByVal lineLen As Integer) As Boolean Dim res As IntPtr Dim wpar As IntPtr = g.GetHdc() Dim lpar As IntPtr = New IntPtr(HundredthInchToTwips(lineLen)) res = SendMessage(Handle, EM_SETTARGETDEVICE, wpar, lpar) g.ReleaseHdc(wpar) Return (Not res.ToInt32() = 0) End Function Public Function FormatRange(ByVal e As PrintPageEventArgs, ByVal charFrom As Integer, ByVal charTo As Integer) As Integer Dim cr As CHARRANGE cr.cpMin = charFrom cr.cpMax = charTo Dim rc As RECT rc.Top = HundredthInchToTwips(e.MarginBounds.Top) rc.Bottom = HundredthInchToTwips(e.MarginBounds.Bottom) rc.Left = HundredthInchToTwips(e.MarginBounds.Left) rc.Right = HundredthInchToTwips(e.MarginBounds.Right) Dim rcPage As RECT rcPage.Top = HundredthInchToTwips(e.PageBounds.Top) rcPage.Bottom = HundredthInchToTwips(e.PageBounds.Bottom) rcPage.Left = HundredthInchToTwips(e.PageBounds.Left) rcPage.Right = HundredthInchToTwips(e.PageBounds.Right) Dim hdc As IntPtr = e.Graphics.GetHdc() Dim fr As sFORMATRANGE fr.chrg = cr fr.hdc = hdc fr.hdcTarget = hdc fr.rc = rc fr.rcPage = rcPage Dim res As IntPtr Dim wpar As IntPtr = New IntPtr(1) Dim lpar As IntPtr = Marshal.AllocCoTaskMem(Marshal.SizeOf(fr)) Marshal.StructureToPtr(fr, lpar, False) res = CObj(SendMessage(Handle, EM_FORMATRANGE, wpar, lpar)) Marshal.FreeCoTaskMem(lpar) e.Graphics.ReleaseHdc(hdc) Return res.ToInt32() End Function Public Function FormatRangeDone() Dim wpar As IntPtr = New IntPtr(0) Dim lpar As IntPtr = New IntPtr(0) SendMessage(Handle, EM_FORMATRANGE, wpar, lpar) End Function End Class End Namespace Now it doesn't display when you do a print preview 'no pages to display'
  23. right should it be like this ? <StructLayout(LayoutKind.Sequential)> _ Private Structure RECT Public Left As Integer Public Top As Integer Public Right As Integer Public Bottom As Integer End Structure
  24. Never messed with structures before in vb.net so how should i go about it?
  25. Its the same control i tried to covert into vb.net above Arh .... no..... Any ideas?
×
×
  • Create New...