Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

One way to do it would be

Dim lines() As String = TextBox1.Lines
lines(3) = "this is actually line 4"
TextBox1.Text = Join(lines, vbCrLf)

Of course, you would get an error if you didn't have enough existing lines. n alternative would be to use a listbox instead and do

ListBox1.Items(3) = "this is line 4"

directly. Same caveat as above.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Any time. Please mark this as solved if we are done.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

When you create a TextBox in the IDE and name it (default is TextBox1) you get an object with that name and you access the methods and parameters with dot notation like TextBox1.Text. Consider the name (or variable) TextBox1 to be just a reference (pointer) to the actual object. Just like if you have an integer variable, x, with the value 5. X is not actually 5, but a reference to some location in memory which contains the value, 5.

If you need to refer to a bunch of text boxes conveniently (like in a loop) then instead of creating individual object references like TextBox1, TextBox2, etc, you can create an array of references as in

Private boxes(5) As TextBox

You haven't actually created the TextBoxes yet. All you have done is create a place to keep references (pointers) to them. Just like there is a difference between

Dim box as TextBox        'declares a TextBox variable
Dim box as New TextBox    'creates a TextBox and saves a reference to it in box

To use the dot notation, the left part of the expression must be a reference to an object. For a single object (like box) you just give the variable name. For an array of objects you have to narrow it down to a single instance. Thus you access a single object by

boxes(i).Text

Just like in an array of integers you can't say

Dim x(5) as Integer

x = 5

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

You could create an array of TextBox references and populate it as you create the controls as in

Public Class Form1

    Private MyText(3) As TextBox

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

        For i As Integer = 0 To 3

            Dim box As New TextBox

            box.Location = New System.Drawing.Point(200, 10 + i * 25)
            box.Size = New System.Drawing.Size(50, 23)

            AddHandler box.TextChanged, AddressOf MyTextTextChanged

            MyText(i) = box
            Me.Controls.Add(box)

        Next

    End Sub

    Private Sub MyTextTextChanged(sender As System.Object, e As System.EventArgs)
        'add your code here
    End Sub

End Class

Then you can refer to the properties (such as Text) in fht eollowing way

MsgBox(MyText(2).Text)
ibeast commented: Perfectly answers my question +1
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Sure. Take the console app:

Module Module1

    Sub Main()

        Dim password As String = "mypass"
        Console.WriteLine("password=" & password)

        password = Chr(115)
        password &= Chr(101)
        password &= Chr(99)
        password &= Chr(114)
        password &= Chr(101)
        password &= Chr(116)
        Console.WriteLine("password=" & password)

    End Sub

End Module

When you run it you will get the output

password=mypass
password=secret

If you extract the string values from the exe file (I use strings.exe, a tool from the excellent SysInternals Suite available free here) you can see the string "mypass" but not the constructed string "secret".

Please note that if you build "secret" in one line of code like

password = Chr(115) & Chr(101) & Chr(99) & Chr(114) & Chr(101) & Chr(116)

The compiler will optimize this to

password = "secret"

and, therefore, the string will be available for detection. The above method does not prevent someone extracting the string by examining the machine code with a disassembler or a debugger but it does add a level of obfuscation to prevent casual sleuthing.

ryklon commented: Your explanation is good. +1
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

If your source code is available to read, I suspect no. String constants in exe files can be easily extracted so if you want to "hide" the password in the exe then you can build it at run time a character or two at a time, even using conversion from numeric values to further obscure the actual password.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

I tried to recreate your database here and ran the insert. It worked. How do you know the data has not been inserted? Do you have SQL Server Management Studio installed? I should disclose that I prefer ADO.Net over OLEDB. I find that fewer layers between my code and the data means less time debugging.

I see your connection string contains.

AttachDbFilename=|DataDirectory|\Database1.mdf;Integrated Security=True;User Instance=True")

I suggest you use

Initial Catalog=Database1;Integrated Security=True;"

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

In what way does it not work? Are you getting an error message? Is the resulting data not what you expect? What are the values of

tbox_username.Text
tbox_password.Text
isAdmin

What is the structure of [login]? I suspect that isAdmin is going into the query as the string "True" or "False". If isAdmin (in the table) is abit value then you will have to translate true/false into 1/0 in the query.

Can't provide definitive help without complete information.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

If I understand correctly, you could save the positions of the panels in My.Settings then restore those positions when you reopen the app.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Have a look here

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

One suggestion is to declare an array of references to panel and assign the panels to the array in the order you want to reference them.

Private panels(2) as Panel

panels(0) = myPanel1
panels(1) = myPanel2
panels(2) = myPanel3
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Go ahead and post the code. It would also help to see the structure of the table. How you set the value of a local boolean for isAdmin will depend on the field type. For example, if isAdmin is a single character field containing "Y" or "N" (and assuming you are using ADO) it would look something like

rset.Open("select isAdmin from mytable where username = '" & username & "'",...

dim admin as Boolean = False

if not rset.EOF then
    admin = rset("isAdmin").Value = "Y"
end if

rset.Close()
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

textbox.Text = (timer1.Elapsed + timer2.Elapsed).ToString

thedonedeal commented: This one works. +2
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Welcome. Don't forget to mark this thread as solved.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Removed. I had a comment but Jx Man beat me to it;)

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

You can replace a single quote with two single quotes before you add the string to the query. For example

insert into table1 (name) values('D''Costa')

If you need to search for fields that contain characters like '%' and '_' you can use the ESCAPE keyword as follows:

select * from table1 where name like '%\_%' ESCAPE '\'

This will return all names containing an underscore. We have defined the backslash as a special character to prevent the underscore in the LIKE clause from being used as a wildcard.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

I wrote a code that stores three names[QUOTE}

Your code actually stores 4 names.

- Make the user select a number (from 1-3) by using a (combobox)
- If the user select the proper number then a message will appear that the name is there.

How do you determine what is a "proper" number? As far as I can tell, the list of names doesn't figure into this at all. If you are trying to search the list of names then you typically are comparing a given name to the names in the list. In your case you are entering a number, not a name. If you are looking for the name that corresponds with the entered number then it not necessary to look. It's in the list at the index that was entered.

Searches on simple lists are usually done in one of two ways. If the list is unordered (yours is unordered because "Bond" occurs before "Black") then you start at the top of the list and compare each entry to the name you are looking for. If you get a match you can stop. If you get to the end of the list then the search failed.

On ordered lists you can use a binary search. In this case you start by comparing the name at the midpoint of the list. If it matches then you are done. If not then you ignore either the first or last half of the list depending on whether the current …

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

counter usually used in loop

There are many times when this is not the case. For example, a Class variable (which is single instance no matter how many times the class is instantiated) to keep track of how many objects of that class have been created.

Final answer? Number 4.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

If pressed, I would say number 4. Counters are incremented by fixed amounts. The increment in number 4 varies depending on the current value of counter. Technically, number 4 could be a counter if (for example) in a loop, the number of things you are counting doubles each time. Then again, you could say number 2 because counters usually count up, however, again, not necessarily true in all cases.

Actually, you were given a pretty dumb question.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

use the SelectedItem property of the combobox to get the value. The selected item is available in the event, ComboBox1.SelectedIndexChanged. If you know that the selected item is integer you can convert it as

dim mynum as Integer = CInt(combobox1.SelectedItem)

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

I'm not sure what you mean by validate the file size. You can get the file size by

My.Computer.FileSystem.GetFileInfo(filename).Length

Typically you would validate it by uploading it then comparing the size of the uploaded file to the size of the local file but you say you want to validate the size BEFORE uploading it.

I also want to mention that the process to transfer a file should be via a temporary file name. For example, if you want to transfer the file "myfile.txt" the process should be

1) transfer "myfile.txt" to "myfile.txt.temp"
2) verify that Size("myfile.txt") = Size("myfile.txt.temp")
2) rename "myfile.txt.temp" to "myfile.txt"

This is done so that if an automated process at the receiving end is watching for "myfile.txt", it doesn't try to process it until after the rename, guaranteeing that the file is available. You'd be surprised how many "professional" developers get this wrong.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

It specifies the actual filename of the SQL database. I have never used this parameter. I specify the server name and database name and let SQL server figure out where the file is stored.

I was a SQL db Administrator (among many other rthings) before I retired, and there were a couple of times when I had to move our database files from one disk to another. Any applications that used the attachdb parameter to connect would have failed. None of them did. I can't think of any reason you would want to use it either.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

You could use an Access database or an Excel spreadsheet. There are connection strings available for both of these. Even CSV files as I recall.

bilal_fazlani commented: experienced..! +2
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

The following code creates an Excel object to access an Excel spreadsheet. It is up to you to determine whether appropriate values are entered in the cells. ListView1 is in Details view and has four columns.

Imports Microsoft.Office.Interop ' requires "Microsoft Excel ## Object Library" resource (COM)
Imports System.Windows.Forms

Public Class Form1

    Private Sub btnImport_Click(sender As System.Object, e As System.EventArgs) Handles btnImport.Click

        Dim xls As New Excel.Application
        Dim sheet As Excel.Worksheet

        xls.Workbooks.Open("d:\temp\test.xls")
        sheet = xls.Workbooks(1).Sheets(1)

        Dim row As Integer = 2
        Dim col As Integer = 1

        Do Until Len(sheet.Cells(row, 1).Value) = 0
            Dim item As New ListViewItem
            item.Text = sheet.Cells(row, 1).Value
            item.SubItems.Add(sheet.Cells(row, 2).Value)
            item.SubItems.Add(sheet.Cells(row, 3).Value)
            item.SubItems.Add(sheet.Cells(row, 4).Value)
            ListView1.Items.Add(item)
            row += 1
        Loop
 
        xls.Workbooks.Close()
        xls.Quit()

        releaseObject(sheet)
        releaseObject(xls)

    End Sub

    Private Sub releaseObject(ByVal obj As Object)

        Try
            System.Runtime.InteropServices.Marshal.ReleaseComObject(obj)
            obj = Nothing
        Catch ex As Exception
            obj = Nothing
        Finally
            GC.Collect()
        End Try

    End Sub

End Class
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

The only part I could offer any help with would be the database part. If you could post the part where you are trying to connect I can have a look.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

What error message do you get when you try to connect? It is possible you don't have the correct access rights or that you misspelled the server name. Try changing the server name from "VNET-PC\SQLEXPRESS" to ".\SQLEXPRESS".

Do you have SQL Server Management Studio installed? Can you verify that you have the correct name for the database?

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Just for my own curiosity, is there any way you could post a hex dump of the saved output text file?

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Sorry to say but it works just fine on my computer. I really have no further ideas.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

I don't think that's the problem because I did exactly what he posted and got the result he wanted.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Can you zip your entire project folder and post it here? I'll download it and see how it behaves on my computer.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

I usually use TextPad instead of Notepad and I have seen multiple lines display as one in notepad when the lines end with a line feed only rather than carriage return+line feed. TextPad doesn't have this problem. What happens if you list the contents of the file from the command line (using the TYPE command)?

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

I set up a test exactly as you specified and my text file contains

A
B
C
D
E
F

Can you possibly post a screenshot of your app running?

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

I tried this on a test sheet and found that when I deleted a cell the field was imported as a null string. You could always scan the data after importing and do an appropriate substitution. Unfortunately the COALESCE function is not available when reading the Excel spreadsheet. If you are not familiar with this, it is a useful feature when qoing a query on SQL databases. COALESCE takes a variable number of parameters and returns the first non-NULL value. For example

SELECT fname,lname,age,COALESCE(salary,0) from mytable

would substitute 0 for the salary in any record where salary was NULL.

If youfind that you are having a problem with NULL values on reading the spreadsheet then I suggest you process the data cell by cell and do your own validation. Do you need some sample code for this?

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

You could build the query like

Dim query As String = "select * from Incidents"

If txtDMA.Text <> "" Or txtStreet.Text <> "" Then
    query &= " where "
    If txtDMA.Text <> "" Then
        query &= "DMA = '" & txtDMA.Text & "'"
    End If
    If txtStreet.Text <> "" Then
        If txtDMA.Text <> "" Then
            query &= " AND"
        End If
        query &= " StreetName LIKE '%" & txtStreet.Text & "%'"
    End If
End If
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

You can get the list of files with

Dim filelist() As String = System.IO.Directory.GetFiles("c:\windows\system32")

Use a class variable to keep track of which file name to display next. The timer tick handler can advance the index (and wrap to zero if you want to repeat).

NetJunkie commented: Thanks! +5
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

On the groupbox or on the labels? Either can be done with AddHandler.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

This will do it quick and dirty

Public Class Form1

    Private groups(3) As GroupBox

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

        Me.SuspendLayout()

        'create 4 groups

        For g = 0 To 3

            groups(g) = New GroupBox

            With groups(g)

                .Text = "Group " & g
                .Size = New System.Drawing.Size(160, 220)
                .Location = New System.Drawing.Point(13 + 165 * g, 13)

                'create 8 labels within this group

                For i As Integer = 0 To 7

                    Dim label As New Label
                    With label
                        .Text = "label " & i
                        .Size = New System.Drawing.Size(60, 13)
                        .Location = New System.Drawing.Point(18, 23 + 25 * i)
                    End With

                    .Controls.Add(label)

                Next

            End With

            Me.Controls.Add(groups(g))

        Next

        Me.ResumeLayout()

    End Sub

    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click

        'change text and colour for the third label in the third group

        With groups(2).Controls(2)
            .Text = "splunge"
            .BackColor = Color.Aqua
        End With

    End Sub

End Class

If you wanted to pretty it up you could define a custom groupbox class which would have an array of labels. Note that when I define the positions of the new labels and group boxes I add a few pixels for spacing (group width is 160 but next width is 13+165*g). You could also (I think) subclass the groupbox control but I've never gotten that fancy and am not familiar with the technique.

This gets a little messier when you want to add handlers for events but this is probably not a concern for just labels.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Not sure how to answer that other than to ask what specific things you expect to be able to do, then address those things one by one. If the data is in a regular format (like a table where all rows are the same) then there should be no problems using OLEDB or ADO. Of course, that's assuming that we are talking about actual data rather than something that makes sense only when in an Excel spreadsheet. If the data is not in a table format and you need to get at specific cells then there are other ways to open the spreadsheet.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Can't do. I've never programmed a web interface. The best I could do was make an off the wall suggestion that I hoped might point you in the right direction.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Completely uneducated suggestion here, but I noticed that the WebBrowser control has a DocumentCompleted event. Why not use that instead of a wait loop?

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

You don't have to shut down and restart. I should have mentioned that while you have the project open, you have to go into the project properties and add appropriately named and typed variables to the Settings tab. For string values you DO NOT put quotes around the text.

As soon as you do My.Settings.Var = value the value is available. For example

My.Settings.Test = "splunge"
MsgBox(My.Settings.Test)

will pop up a box with the text "splunge". Because you want the settings preserved from one run to the next I thought that using My.Settings would more easily accomplish that and also avoid the problem you were having.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

I just thought I'd answer the question you didn't ask. Sorry, but I can't help you with the WebBrowser stuff.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

I'm a little coonfused. Are you getting the parameters from a dialog (form) or froma config file? Can I suggest that instead of a config file you use application settings? That way your code can be

if My.Settings.ServerName = "" Then
    'display dialog box for user to enter server and port info
End If

The dialog that allows the user to enter the server name and port number could save these values back to My.Settings before closing. It would also eliminate the problem with parsing a config file. The values in My.Settings can be on a per user or per application basis.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

The only time I had to scan a large number of items was when I converted all my photo albums to digital. I just bit the bullet and got a scanner with a document feeder (and the software to drive it). I'm out of suggestions. Sorry.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

My apologies. I mistyped the last line of code. It should have had the closing parenthesis inside the quotes as in

& txtTelNumber.Text & "')"

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Use

Query = "INSERT INTO PROD_DB_Complete_Board _
    (ID, [Board Size], Laminate, [Stock Level]) _
    Values('" & TextBox4.Text & "','" _
        & "'" & TextBox2.Text & "','" _
        & "'" & TextBox3.Text & "','" _
        & "'" & TextBox1.Text & "')"

It's easier to see the problem when the fields line up. I don't knkow if you have the option, but I strongly suggest you modify the database so the field names do not contain spaces. You should remove them or replace them with underscores.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Can't comment on the WebBrowser portion but I do have a couple of things to point out. You can replace each block of

If TextBox3.Text = String.Empty Then
    MessageBox.Show("Please enter a subject", "Subject Required", MessageBoxButtons.OK, MessageBoxIcon.Error)
End If
If TextBox3.Text = String.Empty Then Exit Sub

with

If TextBox3.Text = String.Empty Then
    MessageBox.Show("Please enter a subject", "Subject Required", MessageBoxButtons.OK, MessageBoxIcon.Error)
    Exit Sub
End If

Also

For abc = TextBox5.Text To TextBox6.Text Step 1

For loops require integer parameters. You have declared abc as integer, however, TextBox5.Text and TextBox6.Text are not integers. You should convert these to integer values (after ensuring that the strings are in fact valid integers).

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

You can form the insert query by

query = "insert into TABLENAME _
   (CustomerID,Title,FirstName,LastName,DOB,Address,Town,Postcode,County,TelNumber) _
    values('" & txtCustomerID.Text & "','" _
              & txtTitle.Text      & "','" _
              & txtFirstName.Text  & "','" _
              & txtLastName.Text   & "','" _
              & txtDOB.Text        & "','" _
              & txtAddress.Text    & "','" _
              & txtTown.Text       & "','" _
              & txtPostcode.Text   & "','" _
              & txtCounty.Text     & "','" _
              & txtTelNumber.Text  & "')"

Note that VB will reformat the code to remove extra spaces. I left it as above so it would be easier to see how the query is built. How you apply the query to the database depends on how you connected. If you do it with ADO then it would look like

Imports ADODB
.
.
.
conn = New Connection
conn.Open("Driver={SQL Server};Server=.\sqlexpress;Database=mydb;Trusted_Connection=yes;")
query = (use the code from above)
conn.Execute(query)
conn.Close()
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

You are getting txtServerIP.Text and txtServerPort.Text from a different form and it is possible that by the time you try to get these values the form has entered a state where that data is not available. Perhaps it is in the way you are calling frmLogin. Can you post that part of the code, and perhaps the FormClosing part from frmLogin? One of my apps has an edit form that I call repeatedly and I have no problem accessing the fields on the edit form from main after the form is closed.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

You are posting the code with the variables. That's not what I need to see. After line 6 in the above example, please add the line

MsgBox(urlMySQLDatabase1)

and post the result