TnTinMN 418 Practically a Master Poster
   Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
      If Not Char.IsLetterOrDigit(e.KeyChar) Then
         e.Handled = True
      End If
   End Sub
TnTinMN 418 Practically a Master Poster

Do you have a "Button1" on your form or did you name it something else?

Please post your code.

TnTinMN 418 Practically a Master Poster
TnTinMN 418 Practically a Master Poster

It just occured to me that you may be referring to the "PictureBox.Border". Is the Border property set = none?

It would help if you posted a screen shot of the problem.

TnTinMN 418 Practically a Master Poster

VB2005 has VB6 converter built-in. For simple projects it can be a time saver. As the others have stated, the converted source can be more work than starting from scratch.

Here are download links for VB2005.

Visual Basic 2005 Express Edition (445,282 KB)
* IMG File: http://go.microsoft.com/fwlink/?linkid=54764
* ISO File: http://go.microsoft.com/fwlink/?linkid=57033

As far as writing your own converter, you will have the investment in writing the converter itself that I think could be better invested in getting the needed conversions done.

TnTinMN 418 Practically a Master Poster

Add a constructor to the form (call it Form2) that needs to hide the button on the first form (call it Form1). Like this:

Public Class Form2

   Private ButtonToHide As Button

   Public Sub New(ByVal ButtonToHide As Button)
      Me.InitializeComponent()
      Me.ButtonToHide = ButtonToHide
   End Sub

   Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
      ButtonToHide.Hide()
   End Sub
End Class

Then in Form1, call the constructor like this:

Public Class Form1
   Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
      Dim frm As New Form2(Button2)
      frm.Show()
   End Sub
End Class
TnTinMN 418 Practically a Master Poster

Take a look at this article. It's in C#, but you should be able to follow the methodology. If you have problems understanding it, feel free to ask questions here. I have implement his methods in a project of mine, so I have a basic understanding of what it is doing and some of the issues that you may encounter.

TnTinMN 418 Practically a Master Poster

The DLLImportAttribute is used to import a specific function from a native library. It does not import the entire library. You need the documentation for the function to define the signature properly. For imports from Microsoft Windows API's see http://www.pinvoke.net/.

A quick websearch on beidlib.dll leads me to believe that you been asking how to access this library on several forums and finding no joy in doing so. If this is incorrect, please accept my appologies for the inference.

I am assuming that this library is the Belgium Identity Card library. If this is so, then this library may help. http://delphi32.blogspot.com/2008/07/belgian-eid-card-access-sdk.html

TnTinMN 418 Practically a Master Poster

Correction. I should have suggested "StrechImage" instead of "Zoom".

TnTinMN 418 Practically a Master Poster

You may want to take a look at this HTML Render. http://www.codeproject.com/Articles/32376/A-Professional-HTML-Renderer-You-Will-Use

You can use it to render HTML to an bitmap then save the bitmap.

TnTinMN 418 Practically a Master Poster

There should not be a box behide the picture box. Are you sure that you do not have a image smaller than the size of the picturebox and that the PictureBox.SizeMode is not set to centerimage? Try setting the size mode to "Zoom" and see if the box goes away.

TnTinMN 418 Practically a Master Poster

So the short version is If 0 <= a <= 100 Then is equivalent to If (0 <= a) <= 100 Then which is NOT the same as If 0 <= a And a <= 199 Then

Correct. The first conparison evaluates to a boolean result. It is no different than:

Dim b as Boolean = 0 < a
If b < 100 Then 'again assuming Option Strict Off
or
If True < 100 Then
or 
If False < 100 Then

For those interested, here are some "Between" extensions from one of my pet projects. Beware that these have not been fully tested yet.

Module myExtensions
#Region "Numeric ValueType Between Methods"
   'ToDo:  Finish stress testing Between.  Verify no loss of magnitude for conversion to Double or Decimal.

   'Reference:  Widening and Narrowing Conversions
   '            http://msdn.microsoft.com/en-us/library/k1e94s7e.aspx

   ''' <summary>Not Valid for nonnumeric value types including Boolean and user defined Structures.  Will throw runtime error on nunnumerics.</summary>
   <System.Runtime.CompilerServices.Extension()> _
   Public Function IsBetween(ByVal value As ValueType, ByVal Start As ValueType, ByVal [End] As ValueType) As Boolean
      If Not CorrectOrder(value, Start, [End]) Then
         Throw New ArgumentException("Start Value must be <= End Value")
      End If
      If ValidCompareType(value.GetType) AndAlso _
         ValidCompareType(Start.GetType) AndAlso _
         ValidCompareType([End].GetType) Then
         If UseDecimal(value) Then
            Return CDec(Start) < CDec(value) AndAlso CDec(value) < CDec([End])
         Else
            Return CDbl(Start) < CDbl(value) AndAlso CDbl(value) < CDbl([End])
         End If
      Else
         Throw New ArgumentException("Invalid comparison type")
      End If
   End Function

   ''' <summary>Not Valid for nonnumeric value types including Boolean and user defined Structures.  Will …
TnTinMN 418 Practically a Master Poster

I just realized that I made mistake in my first response to you. The textbox is updating as you append text in your loop. These updates are very resource intensive. If you can live with updating every "X" lines, then this modifcation will give you even better performance. The larger "X" is (less repainting the textbox) the faster your code will proceed.

Dim counter as Int32 = 0
TextBox1.AllowRedraw(False)
For Each TextLine In ArrayList

... Your Code


If counter Mod 5 = 0 Then 'update every 5 lines process
   TextBox1.AllowRedraw()
   TextBox1.AllowRedraw(False)
End If

Next

TextBox1.AllowRedraw() ' make sure to re-enable redraw

Where the AllowRedraw Method is an extension method defined as:

Module MyExtensions
   Private Const WM_SETREDRAW As Int32 = &HB
   <System.Runtime.CompilerServices.Extension()> _
   Public Sub AllowRedraw(ByVal cntrl As Control, Optional ByVal allow As Boolean = True)

      If allow Then
         SendMessage(cntrl.Handle, WM_SETREDRAW, New IntPtr(1), IntPtr.Zero)
         cntrl.Refresh()
      Else
         SendMessage(cntrl.Handle, WM_SETREDRAW, IntPtr.Zero, IntPtr.Zero)
      End If
   End Sub

   <Runtime.InteropServices.DllImport("user32.dll", SetLastError:=True, CharSet:=Runtime.InteropServices.CharSet.Auto)> _
   Private Function SendMessage(ByVal hWnd As IntPtr, ByVal Msg As Int32, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As UInt32
   End Function
End Module

Just add this module to your project. It's one of my favorite tricks to speed things up.

TnTinMN 418 Practically a Master Poster

VB.net should be able to handle this although you may have to use parenthesis: If (0<= a <=100) then AND, ANDALSO, OR and ORELSE are used for testing two conditions but "0<=a<=100" is one logical condition

This will compile and run if "Option Strict" is off (one of the many reasons to always set Option Strict On), but it will always equate to True.

"0 < a" will be evaluated first and result in a boolean value; this value will be converted to a numeric value of either 0 (false) or -1 (true) and the compared against "< 100". Both 0 and -1 are less than 100, hence the true result.

TnTinMN 418 Practically a Master Poster

Sometimes the designer gets messed up and exiting and restarting clears it up. Best to make sure the Form's Design view is closed before restarting.

In the worst case you may have to edit the Form.designer.vb file and make sure that the controls are added to the proper tabpage. If you do this, make the edits, save them, then close the file and then open up the form in design view.

TnTinMN 418 Practically a Master Poster

Two things standout as big performance hits:
1) string concatenation: This is very slow and gets worse as the length of the string grows. Your "Display" variable gets longer as the loop progresses.

2) unnecessary assignment statements in the loop: The big one is assigning TextBox1.Text. Since you have not issued a TextBox1.Refresh command after the assignment, I assume that you can wait until the loop finishes to view the results. The minor assigment is the "btn2003.Ennabled"

No guaranty of major performance improvement, but I reccommend that you use a System.Text.StringBuilder for "Display" and modify the logic as follows:

        Try

            Dim Display As New System.Text.StringBuilder(100) 'adjust this initial size (100) to what makes sense
            textbox1.Text = n1 & vbNewLine 'initialize the textbox's text
            btn2003.Enabled = False
            For Each TextLine In ArrayList

                ' Dim tmp() As String = Split(TextLine)
                Dim split As String() = TextLine.Split(New [Char]() {"/"c})
                ipaddress = split(0)
                subnet = split(1)
                If subnet.Contains("32") Then
                    subnet = subnet.Replace("32", "255.255.255.255")
                    .
                    . the rest of the "if-then" block
                    .
               Display.Length = 0 ' clears the stringbuilder
               With Display
                  .Append(p1)
                  .Append(p2)
                  .Append(P3)
                  .Append(ipaddress)
                  .Append(p4)
                  .Append(subnet)
                  .Append(p5)
                  .Append(p6)
                  .AppendLine(p7)

               End With

                'let the textbox append the text, this eliminates a couple to string copys that can be quite long
                textbox1.AppendText(Display.ToString)

            Next
            btn2003.Enabled = True  'If this is the correct spot        

Also, what does this function return?

TnTinMN 418 Practically a Master Poster

You have not assigned the connection to "OComn" (OleCoDbCommand).
see: http://msdn.microsoft.com/en-us/library/system.data.oledb.oledbconnection%28v=vs.90%29.aspx

TnTinMN 418 Practically a Master Poster

What I want to have is the inverted output e.g. binary output converted from 000010001000011 (abc) to 000110001000001 (cba).

For i = 0 To stringlength - 1


            If c = "0" Then
                convertdata = "00000"
.... rest of your code


Should be something like this:

Dim stringlength as Int32 = StringToConvert
Dim c as string
For i = 0 To stringlength - 1
    c = StringToConvert(i)

            If c = "0" Then
                convertdata = "00000"
.... rest of your code


To just the reverse result, just change the "For" statement to:
For i = stringlength - 1 to 0 Step -1

I was bored so I wrote you this Function to show you another approach. I am not saying it is better. It is just a different way of doing it.

Private Function MyBinary(ByVal s As String) As String

   Dim alphaOffset As Int32 = Asc("a") - 1

   Dim bits As Int32
   Dim charbits(0 To 4) As Char ' your bit pattern has 5 positions

   ' A StringBuilder is just a class that manages a character array for you
   ' since we can calculate how many characters there will be,
   ' initialize the StringBuilder to this known length
   Dim binary As New System.Text.StringBuilder(s.Length * 5)

   For i As Int32 = s.Length - 1 To 0 Step -1
      If IsNumeric(s(i)) Then
         bits = Int32.Parse(s(i))
         If bits > 4 Then Throw New ArgumentException("Invalid character: " & bits.ToString)
         If bits > 0 Then bits += 26
      Else
         If s(i) < …
TnTinMN 418 Practically a Master Poster
TnTinMN 418 Practically a Master Poster

You did not mention what tutorial you are following. However, I have found this site to be very good, if at times dated, for learning the basics.
http://www.homeandlearn.co.uk/NET/vbNet.html

It would also be helpful if you posted a screen shot of your database definition. From the code you posted, you have obviously figured out how to use the wizards to create a datasource and drag it to the form to create a bound datagridview. If you go to the Solution Explorer Window, you should see a file listed with the extension "xsd". Double-click on that and take screen shot and post it. That way we can see your table definition.

Also please state what your goals are.

TnTinMN 418 Practically a Master Poster

Personally, I prefer to prevent the user from having such entry options. It makes the subsequent coding much easier. It is easy enough to write custom entry controls that inherit from those supplied in .Net.

I have assumed that you want to be able to enter N=North, S=South, E=East, W=West for the first character position and that you only want to allow up to 3 digits to follow that.

To accoplish this, I start off with a MaskedTextBox with the proper mask. I override the ONKeyPress to limit the first letter entered. The ONKeyDown override prevents the user from entering spaces. WndProc handles the user pasting invalid characters.

Just copy this code to your project and rebuild it. If your have Visual Studio set up to automatically add UserControls to the toolbox, it should show up in the toolbox.

Public Class CoordinateTB
   Inherits MaskedTextBox
   Public Sub New()
      Me.PromptChar = " "c 'I hate that default underscore
      Me.Mask = ">L0##" ' 1st char is letter converted to uppercase
                        ' followed by 3 digits, last 2 are optional
   End Sub

   Private Const AcceptableChars As String = "NEWSnews0123456789"
   ' This is to further filter the allowed characters
   ' I assumed that you want to be able to enter N=North, S=South, E=East, W=West
   ' for the 1st character.  AcceptableChars has both the Upper and Lower case 
   ' representations of the letters.  The Mask will convert it to Uppercase.
   Protected Overrides Sub OnKeyPress(ByVal e As System.Windows.Forms.KeyPressEventArgs)
      If Acceptablechars.Contains(e.KeyChar) Then
         MyBase.OnKeyPress(e)
      Else
         e.Handled = True …
TnTinMN 418 Practically a Master Poster

Take a look at this article.

TnTinMN 418 Practically a Master Poster

To be honest, I got a little confused by your logic. Therefore I thought I would post this example. It is similar to yours and maybe you can use it to find the problem in your code.

string path = Application.StartupPath + "\\songs.txt";
System.IO.Stream strmSongs = System.IO.File.OpenRead(path);
System.IO.StreamReader sr = new System.IO.StreamReader(strmSongs);

string[] Songs = new string[100];            //initially allow for 100 songs
Int32[] Votes = new Int32[100];
string line = null;

Int32 count = 0;
while (sr.Peek() != -1)
{
    line = sr.ReadLine();
    string[] parts = line.Split(':');
    if (parts.Length != 2)
    {
        //bad line of data

    }
    else
    {
        if (count == Votes.Length)
        {
            //array is not big enough, make room for 20 more entries
            Array.Resize(ref Songs, Songs.Length + 20);
            Array.Resize(ref Votes, Votes.Length + 20);
        }
        Songs[count] = line;
        Votes[count] = Int32.Parse(parts[1]);
        count += 1;
    }

}

//trim the arrays if necessary
if (count != Songs.Length)
    Array.Resize(ref Songs, count);
if (count != Votes.Length)
    Array.Resize(ref Votes, count);

sr.Close();

Array.Sort(Votes, Songs);
TnTinMN 418 Practically a Master Poster

A BindingSource also has a "Sort" property.

I have not investigated the actual logic for this, but if the bindingsource.sort property is set to an empty string, the behaviour your are seeing will occur.

If you set bindingsource.Sort to null before assigning the "DataSource", it will not clear the DefaultView.Sort value.

TnTinMN 418 Practically a Master Poster

Sandy,

First off, change the password on that account immediately and cancel your credit card.

I know very little about this topic, but:

Dim em1 As HtmlElement = wb1.Document.All("emailAddress")
'returns ID: "login-Email_Address" 

Dim pw As HtmlElement = wb1.Document.All("password")
'returns ID: "login-password"

These are not the ID's you wanted.

This does work though:

Dim inputs As HtmlElementCollection = wb1.Document.GetElementsByTagName("INPUT")
Dim emSet, pwSet As Boolean
For Each el As HtmlElement In inputs
   Select Case el.Id
      Case "emailAddress"
         el.SetAttribute("Value", "sge")
         emSet = True
      Case "password"
         el.SetAttribute("Value", "7476")
         pwSet = True
   End Select
   If emSet And pwSet Then Exit For
Next
wb1.Document.GetElementById("loginButton").InvokeMember("click")
TnTinMN 418 Practically a Master Poster

Unfortunately, Access does not support the DateName function. However, you can get the same functionality from the "FORMAT" function.

Dim conn As New OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source='" & "D:\My Documents\temp\Play.mdb" & "'")
Dim cmd As New OleDb.OleDbCommand()
cmd.Connection = conn


TextBox1.Text = "ma"
cmd.CommandText = "SELECT *, FORMAT([DateEntered], 'MMMM') as [Month] FROM FilterOnDate WHERE UCASE(FORMAT([DateEntered], 'MMMM')) LIKE '" & TextBox1.Text & "%'"

conn.Open()
Dim dt As New DataTable
dt.Load(cmd.ExecuteReader(CommandBehavior.Default))
conn.Close()
DataGridView1.DataSource = dt
TnTinMN 418 Practically a Master Poster

I would suggest that you place your logic in the PlayStateChange event handler. Here is a snippet from a program of mine.

   Sub WMP1_PlayStateChange(ByVal sender As Object, _
         ByVal e As AxWMPLib._WMPOCXEvents_PlayStateChangeEvent) _
         Handles wmp1.PlayStateChange

         Select Case e.newState

            Case WMPLib.WMPPlayState.wmppsUndefined
            currentStateLabel.Text = "Undefined"

            Case WMPLib.WMPPlayState.wmppsStopped
            currentStateLabel.Text = "Stopped"

            Case WMPLib.WMPPlayState.wmppsPaused
            currentStateLabel.Text = "Paused"

            Case WMPLib.WMPPlayState.wmppsPlaying
               currentStateLabel.Text = "Playing"
               SetSelectedPlayListItem()

            Case WMPLib.WMPPlayState.wmppsScanForward
            currentStateLabel.Text = "ScanForward"

            Case WMPLib.WMPPlayState.wmppsScanReverse
            currentStateLabel.Text = "ScanReverse"

            Case WMPLib.WMPPlayState.wmppsBuffering
            currentStateLabel.Text = "Buffering"

            Case WMPLib.WMPPlayState.wmppsWaiting
            currentStateLabel.Text = "Waiting"

            Case WMPLib.WMPPlayState.wmppsMediaEnded
            currentStateLabel.Text = "MediaEnded"

            Case WMPLib.WMPPlayState.wmppsTransitioning
            currentStateLabel.Text = "Transitioning"

            Case WMPLib.WMPPlayState.wmppsReady
            currentStateLabel.Text = "Ready"

            Case WMPLib.WMPPlayState.wmppsReconnecting
            currentStateLabel.Text = "Reconnecting"

            Case WMPLib.WMPPlayState.wmppsLast
            currentStateLabel.Text = "Last"

            Case Else
            currentStateLabel.Text = ("Unknown State: " + e.newState.ToString())

         End Select
   End Sub
TnTinMN 418 Practically a Master Poster

I'm not sure that I understand what it is that you mean by "own session"

If you mean that you want to merge the two datatables together so that they can be displayed in the same DataGridView control, then you would use the DataTable.Merge method. Perform the merge in your worker thread's completed event handler.

TnTinMN 418 Practically a Master Poster

You could accomplish your goal via Reflection something like this:

private bool fred;
public void SetBoolean(string boolToSet, bool Value)
{
    System.Reflection.FieldInfo fi = this.GetType.GetField(boolToSet, Reflection.BindingFlags.Instance | Reflection.BindingFlags.NonPublic | Reflection.BindingFlags.Public);
    fi.SetValue(this, Value);
}
public void test()
{
    SetBoolean("fred", true);
}

However, I would recommend that you consider using a Dictionary(Of String, Boolean) instead. It will give you the access by name feature that you want.

TnTinMN 418 Practically a Master Poster

You are not clearing MyDataTable before filling in CnScrip.
Try adding MyDataTable.Clear before MyAdapter.Fill(MyDataTable).

TnTinMN 418 Practically a Master Poster

Based on my interpretaion of your assignment instructions, you need to create a class that defines an aircraft (let's call this class: Aircraft). This class would have three properties that define the aircraft: 1)Name, 2) TakeOfffVelocity, and 3) Acceleration. You also need to define a property two calculated properties: 1) TimeToReachTakeOffVelocity and 2) TakeOffDistance.

In this class you also need to override the ToString Function such that it returns only the Name Property.

Now, I'm just guessing, but in your form you will need to define an array or list of Aircraft (suggest you use a list if possible). You need to also include the array definitions that you previously had for: 1) Names, 2) TakeOffVelocity, and 3) TakeOffVelocity. You are to iterate through these arrays to fill the list.

You then need to set a combox's "DataSource" property equal to your list. This is where the overriden "ToString" comes into play. It provides the combobox a way of displaying the List (of Aircraft) in a meaningful way.

So hopefully without writing the for you, I have given a word statement that you can follow.

TnTinMN 418 Practically a Master Poster

Nutster, you may find this article helpful: Click Here

The code placed under the "Finally" section can be viewed like an in-place method definition that will always be called before leaving the "Try-End Try" block.

Let's say in your IOException example, that you can not recover from the file error and need to return control to the calling procedure via an "Exit Sub", "Exit Function", or "Return" statement. The "Finally" code will execute before the return. You could accomplish the same thing without using the "Finally" section, but it keeps the logic all together and easier to maintain.

TnTinMN 418 Practically a Master Poster

The Form.Close method does exactly that; it tells the form to close. It does not stop the currently executing code block. The following code will demonstrate this behavior and show you an alternative to achieve your goal of stoping execution. Just step through the code in the debugger to observe how the code execution branches and returns.

Public Class Form1
   Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
      CheckFiles()
      Stop 'this line will be reached

   'This will exit the executing code block on return.  
   'Since the main form is closed, the program will terminate.
      If Not CheckFilesV2() Then Exit Sub

      Stop 'this one will not
      MsgBox("hi")
   End Sub

   Private Sub CheckFiles()
      CloseForm()
      Stop 'and here
   End Sub

   Private Function CheckFilesV2() As Boolean
      CloseForm()
      Stop 'and here
      Return False
   End Function

   Private Sub CloseForm()
      Me.Close()
      Stop 'yep you got here
   End Sub
End Class
TnTinMN 418 Practically a Master Poster

It's really pretty simple.

Steps:

  1. Goto your Report in design view and hit the F4 key to bring up the property window for the report.

  2. You need to define a ReportParameter. Click on the elipsis next to the ReportParameters field in the property windows. This will bring up the "Report Parameters" dialog box. Click "Add" then "OK". This will add a string parameter with name "Report_Parameter_0". You can change the name later.

  3. Now click on your textbox and hit the "F4" key again if needed to view its properties. We are interested in the "Value" property. Enter this for the value. You could also use the expresion builder dialog.

    =Parameters!Report_Parameter_0.Value

Now your textbox is setup to set the value from code.

  1. Now for the code to set the parameter. Make sure that you project has a Reference to "Microsoft.Reporting.WinForms"; it should since you already have added the reportviewer control.

I am assuming that your reportviewer is named "ReportViewer1" and the DateTimePicker is named "DateTimePicker1".

      'Define an array to hold the parameter definintion.  
      'This could also be a List(of Microsoft.Reporting.WinForms.ReportParameter)
      'or any class that implements IEnumerable
      'Since I am assuming you have only 1 report parameter, the array will have size=1
      'If you have other parameters, size the array appropriately and define a value for
      'all parameters.  Afterwards, You can set an individual parameter of a multi-parameter report
      Dim params(0) As Microsoft.Reporting.WinForms.ReportParameter

      'The value can only be set in the ReportParameter constructor …
TnTinMN 418 Practically a Master Poster

Usually, the best place to start is to get the manual.

From the manual page 59.

A. What is Dual BIOS Technology ?
Dual BIOS means that there are two system BIOS (ROM) on the motherboard, one is the Main BIOS and the other is Backup BIOS.

Under the normal circumstances, the system works on the Main BIOS. If the Main BIOS is corrupted or damaged, the Backup BIOS can take over while the system is powered on. This means that your PC will still be able to run stably as if nothing has happened in your BIOS.

B. How to use Dual BIOS and Q-Flash Utility?
a. After power on the computer, pressing <Del> immediately during POST (Power On Self Test) it will allow you to enter Award BIOS CMOS SETUP, then press <F8> to enter Flash utility.

I wish you Good Luck with this.

TnTinMN 418 Practically a Master Poster

taskman,
I believe that the OP found the this article: "Error message "Cannot open file <path>\xxx.DBC" reading Microsoft Visual FoxPro tables via the VFP OLE DB Provider" that shows the posted code solution. It is for dealing with the situation where you do not have the "dbc" file.

I question if this would even be necessary if you where to use one of the other drivers to access the records. I doubt that they would be aware of the "backlink" record in the dbf.

+1 for the concerns you raised.

taskman commented: Thanks for the clarification & link +0
TnTinMN 418 Practically a Master Poster

Here is an example that shows four methods to access a "dbf" file. Since you started with OBDC and wanted info on that, that section is quite long. Personally, I would use the ACE driver, but to each their own. The simplest/most flexible for "dbf" is the visual foxpro driver. I cover handling deleted records in the "dbf" because this is an area that can cause those that need to access them quite a bit of headaches. Delete records are not deleted from the file until in is "packed".

Public Class Form1

   Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

      'My dBase files are in the application folder
      Dim AppDir As String = My.Application.Info.DirectoryPath

      '=======================================================
      'Open Database Connectivity (ODBC) DSN-Less Connection
      'see: http://support.microsoft.com/kb/310985

      Dim connSB As New Odbc.OdbcConnectionStringBuilder()
      With connSB
         'these parameters are called "Connection String Attributes"
         'They are driver specific.  

      'see: Initializing the dBASE Database Driver
      '     http://office.microsoft.com/en-us/access-help/initializing-the-dbase-database-driver-HP001032158.aspx

      'see: SQLConfigDataSource (dBASE Driver) 
      '     http://msdn.microsoft.com/en-us/library/windows/desktop/ms710137%28v=vs.85%29.aspx

         .Add("DRIVER", "Microsoft dBase Driver (*.dbf)")
         .Add("DefaultDir", AppDir) 'Path to dbase files
         .Add("FIL", "dBase 5.0") 'File type dBase III, dBase IV, or dBase 5
         .Add("DriverID", 533) '21 (dBASE III), 277 (dBASE IV), 533 (dBASE 5.0)

         'Do not load deleted records.  
         'Tag would be better named "IgnoreDeleted"
         'where 0 = Off, 1 = On
         'My experience is that this tag does not work unless the application is running 
         'with full administrator privilages
         'a work around is presented next
         .Add("DELETED", 0)

         .Add("CollatingSequence", "ASCII") 'can be: ASCII (the …
TnTinMN 418 Practically a Master Poster

How would I go about placing the title into a label first, then sorting and placing all of the other information into the textbox. Sorry to keep asking questions, but reading and sorting from text files is something I am finding hard to figure out.

Hi Minko,

I can sympathize with your problems with text files. I personally prefer to use a binary file as you don't need to go through all the conversions and the loss of floating point accuracy.

But that is not what you need today, so here is a revised version of my example that will process a text file. Most of the code in the subroutine to read the text file is error checking and handling. I added this just to give you an idea how to accomplish some of that. The checking is not exhaustive, but it covers most of the problems that might be encountered. I also added a short function to the Data class to format it as a string.

Public Class Form1

   Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

      'ignore the next line, I need this to test for your date format. 
      'You should delete it
      Threading.Thread.CurrentThread.CurrentCulture = New Globalization.CultureInfo("en-GB")

      Dim myArray() As Data = GetDataFromFile("data.txt", Label1.Text)
      If myArray IsNot Nothing Then 'sucessfully read file
         Array.Sort(myArray)
         TextBox1.Text = ""
         For i As Int32 = 0 To UBound(myArray)
            TextBox1.Text &= myArray(i).FormattedString & vbCrLf
         Next
         TextBox1.SelectionStart = 0 'move cursor to start of text
      Else …
TnTinMN 418 Practically a Master Poster

Does this make things more clear? Perhaps I misunderstood your original request.

The Except method is described here: Click Here

   Dim A() As String = IO.File.ReadAllLines("fileA")
   Dim B() As String = IO.File.ReadAllLines("fileB")

   Dim InA_notIn_B() As String = A.Except(B).ToArray 
   Dim InB_notIn_A() As String = B.Except(A).ToArray


   If InA_notIn_B IsNot Nothing Then
      IO.File.WriteAllLines("InA_notInB", InA_notIn_B)
   End If

   If InB_notIn_A IsNot Nothing Then
      IO.File.WriteAllLines("InB_notIn_A", InB_notIn_A)
   End If
TnTinMN 418 Practically a Master Poster

I just realized that I had this line in the code above: myArray(4) = New data(#3/1/2001#, 1005)

It should have been: myArray(3) = New data(#3/1/2001#, 1005)

TnTinMN 418 Practically a Master Poster

Guys,
this has nothing to do with nulls being returned from the database. It has to to do with the DataTable.Compute method returning a DBNull.Value when as the OP stated that the filter criteria does not match any records in the datatable.

Replace the textbox.text assigment statement with:

Dim o as Object = myTable.Compute("SUM(PercentageInMix)", "ProductCode = '" & txtProductCode.Text & "' ")
RadTextBox8.Text = If(IsDBNull(o), String.Empty, CType(o, String))
TnTinMN 418 Practically a Master Poster

Hi Minko,

You did not show how you defined your array so I had to guess. If you have a one dimensional array you can use the Array.Sort method. I defined a class to hold you data and made an array of those data items. Since the array holds a user defined class, it is necessary to define a way to compare them. The comparer is defined in the class. By implementing the Icomparable interface, it is possible to define a default comparer. It is also possible to specify a specific compare to use.

Public Class Form1

   Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
      'create an array with 4 items
      Dim myArray(0 To 3) As data
      'create something to work with
      myArray(0) = New data(#3/1/2011#, 13)
      myArray(1) = New data(#2/1/2003#, 15)
      myArray(2) = New data(#3/1/2001#, 1000)
      myArray(4) = New data(#3/1/2001#, 1005)

      Array.Sort(myArray) 'use default comparer (ascending) defined in class
         'or
      Array.Sort(myArray, AddressOf data.Sort_Descending) 'specify a sort order

   End Sub

   Private Class data
      Implements IComparable(Of data)
      Public dt As Date
      Public data As Int32
      Public Sub New(ByVal dt As Date, ByVal data As Int32)
         Me.dt = dt.Date 'force date component only just in case datetime value given
         Me.data = data
      End Sub

      'default comparer ascending on date
      Public Function CompareTo(ByVal other As data) As Integer Implements System.IComparable(Of data).CompareTo
         If Me.dt = other.dt Then
            'sort ascending on data
            Return Me.data.CompareTo(other.data)
         Else
            Return Me.dt.CompareTo(other.dt) 'ascending order
         End If
      End Function

      Public Shared Function Sort_Ascending(ByVal x As data, …
TnTinMN 418 Practically a Master Poster

The problem is caused by: ListBox1.Items.RemoveAt(ListBox1.SelectedIndex)
When you remove the item, there is nothing selected and SelectedIndex = -1.

That explains the error, but I have a feeling that your program logic may not be correct.
Is the listbox used to select the meals or is it selected by the combobox and added to the listbox with your "Add" button? The latter case makes sense to me. However, you are traping a change in the listbox and setting the text of the combobox.

TnTinMN 418 Practically a Master Poster

FoxPro uses a variant of the old dBase(Click Here) file format. There is a program (free trial) called DBF Manager that works well with these file types.

You can find it here:
Click Here

TnTinMN 418 Practically a Master Poster

Hi,

Since you are a student, I wanted to show you two other methods for reading a text file as you have described. The second one is just for fun; I would not recommend it.

For your needs the ReadAllLines method shown by Jim is fine, but if the file is large you are unnecessarily storing a large amount of text. Additionally the maximum size of .Net object (string) is 2 GB (1Gig of unicode characters), so it could become an issue.

   Private ValueArray() As Int32
   Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
      Dim values As New List(Of Int32)
      Dim fs As IO.Stream = IO.File.OpenRead("data.txt") 'open file in the executable folder
      Dim sr As New IO.StreamReader(fs) 'create a stream reader to read the file
      Dim line As String
      While sr.Peek >= 0
         Try
            line = sr.ReadLine
            values.Add(CType(line, Int32))
         Catch ex As Exception
            'skip line
            'could display message about bad data
            'MsgBox("bad data:  " & line)
         End Try
      End While
      sr.Close()

      'put the values into the array per your assignment
      ValueArray = values.ToArray
   End Sub

   Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
      'for a blast from the past
      Dim values As New List(Of Int32)
      Dim fn As Int32 = Microsoft.VisualBasic.FreeFile
      Microsoft.VisualBasic.FileOpen(fn, "data.txt", OpenMode.Input)
      Dim line As String
      While Not Microsoft.VisualBasic.EOF(fn)
         Try
            line = Microsoft.VisualBasic.LineInput(fn)
            values.Add(CType(line, Int32))
         Catch ex As Exception
            'skip line
            'could display message about bad data
            'MsgBox("bad data:  " & line)
         End Try
      End While
      Microsoft.VisualBasic.FileClose(fn)

      'put …
TnTinMN 418 Practically a Master Poster

I have done some testing on this method. If the program that you want to append the button to is a .Net application it will not work. It crashes on SetParent. It appears as if there is something built in to prevent this. It is probably a good thing as this type of thing could be used for mischief. If it is another type of program, then you may need to use the API function FindWindowEX to seek the window based on its class and/or caption and use the result instead of Slave.MainWindowHandle.

These types of manipulations typically take a lot of trial and error to get working correctly. There used to be a control from MS to host office applications in a WinForm, but MS withdrew it due too to many problems with it.

So all I can suggest is use what I have shown as starting point and experiment. You may not be successful in the end though.

TnTinMN 418 Practically a Master Poster

Just extract the zip file to where ever you want the files. Then in VB2010 go to the menu File->>Open Project and navigate to where you stored the files. Just keep opening the folders until you are presented with the file "Example UserSetting DataTable.sln". Double-click on it.

TnTinMN 418 Practically a Master Poster

Isn't the correct syntax: System.IO.File.AppendAllText(filepath, strToAppend)

not: System.IO.File.AppendAllText(strToAppend)?

TnTinMN 418 Practically a Master Poster

I followed TnTinMN's suggestion (adding 'dns=' to the beginning

Sorry about this, but I made a typo: it should have been "dsn" not "dns"

TnTinMN 418 Practically a Master Poster

It is all still valid. You should be able to open the project I provided, it will just "upgrade" the solution file. Code is code.