poojavb 29 Junior Poster

Try textbox_TextChangeEvent

Label1.Text=Textbox1.text
poojavb 29 Junior Poster

ur pie variable sets a new form every time so the value in the old form1 does not get updated

Comment the statement where u have declared the pie variable and just call the form name where u are declaring the variable to label
Like below

 'Dim pie As New Form1
          If ListBox1.SelectedIndex = 0 Then
               label1.text = 50
               Form1.Label1.Text = Label1.Text
               Me.close()
          ElseIf Listbox1.SelectedIndex = 1 Then
               label1.text = 75
               Form1.Label1.Text = Label1.Text
               Me.close()
          ElseIf ListBox1.selectedIndex = 2 Then
               label1.text = 100
               Form1.Label1.Text = Label1.Text
               Me.close()
          End If
poojavb 29 Junior Poster

Try this

import java.applet.Applet;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.List;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
// <applet code="AppletInterfaz" width="300" height="200"> </applet>
public class AppletInterfaz extends Applet implements ItemListener {
    List colors;
    public AppletInterfaz() {
        colors = new List(4);
        colors.add("Aqua");
        colors.add("Black");
        colors.add("Blue");
        colors.add("Fuchsia");
        colors.add("Gray");
        colors.add("Green");
        colors.add("Lime");
        colors.add("Maroon");
        colors.add("Navy");
        colors.add("Olive");
        colors.add("Purple");
        colors.add("Red");
        colors.add("Silver");
        colors.add("Teal");
        colors.add("White");
        colors.add("Yellow");
        add(colors);
        //colors.setSelectedIndex(0);
        colors.addItemListener(this);
    }
    public void itemStateChanged(ItemEvent ie) {
        repaint();
    }
    public void paint(Graphics g) {
        //colors.setSelectedIndex(colors.getSelectedIndex());
        int choice;
if (colors.getSelectedIndex()<= -1 )
{
    choice = colors.getSelectedIndex()+1;
}
else
{
    choice = colors.getSelectedIndex();
}
        System.out.println(choice);
        int red, green, blue;
        int colorMix[][] = { { 0, 255, 255 }, { 0, 0, 0 }, { 0, 0, 255 },
                { 255, 0, 255 }, { 128, 128, 128 }, { 0, 128, 0 },
                { 0, 255, 0 }, { 128, 0, 0 }, { 0, 0, 128 }, { 128, 128, 0 },
                { 128, 0, 128 }, { 255, 0, 0 }, { 192, 192, 192 },
                { 0, 128, 128 }, { 255, 255, 255 }, { 255, 255, 0 } };
        red = colorMix[choice][0];
        green = colorMix[choice][1];
        blue = colorMix[choice][2];
        Color fondo = new Color(red, green, blue);
        g.setColor(fondo);
        g.drawRect(0, 0, 300, 200);
        g.fillRect(0, 0, 300, 200);
    }
}

Actually ur choice variable gets value as -1 so it shows the error of OutofIndex....since no item is selected in the List...
bydefault select some item in the List and then assign the value to choice variable....

Kronolynx commented: thanks for the help +0
poojavb 29 Junior Poster
 MessageBox.Show("WELCOME TO MAGIC BEANS INC. ^_^ :* :)) :p", Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Information)
          Dim button As DialogResult
          button = MessageBox.Show("Would you like to become a member? (note: membership fee Php 500, non-member 250 for)", Me.Text, MessageBoxButtons.YesNo, MessageBoxIcon.Information)
          If button = Windows.Forms.DialogResult.Yes Then
               Me.Show()
               'Me.Dispose(False)
          ElseIf button = Windows.Forms.DialogResult.No Then
               Form2.Show()
               Me.Dispose(False)
          End If
gelmi commented: haha laughing at myself right now. Thanks anyway :) +0
poojavb 29 Junior Poster

Try something like this

Private Sub FindMySpecificString(ByVal searchString As String)
   ' Ensure we have a proper string to search for.'
   If searchString <> String.Empty Then

       Dim index As Integer = listBox1.FindStringExact(searchString)
       ' Determine if a valid index is returned. Select the item if it is valid.'
       If index <> ListBox.NoMatches Then
          ListBox1.SetSelected(index, True)
          MsgBox("Got it")
       Else
          MsgBox("The search string did not find any items in the ListBox")
          TextBox4.Text = "" 'the textbox u require
       End If
   Else
       MsgBox("Empty")
   End If
End Sub

call this function in the button click event

poojavb 29 Junior Poster

U have two variables

Dim total as Integer and it wont be accessible
Public tolal as Double is accessible

but in your code

 Public tolal As Double ' tolal is public
 Form18.total = Module1.dailytotalamount ' total is not public....

u have declared tolal as public but not total

Begginnerdev commented: What I figured! Very nice, pooja! +6
poojavb 29 Junior Poster

using select statement and in the where clause mention the criteria as ur combo box....and in ur reader assign the value to the text box....

 Try
     Dim myCommand As SqlCommand
     myCommand = New SqlCommand("SELECT  * FROM tablename where studentname='" & Combobox1.Text & "'", Connection)
     Dim reader As SqlDataReader = myCommand.ExecuteReader
     While reader.Read
           txtRollID.Text = reader("RollID")
     End While
     reader.Close()
Catch ex As Exception
     MsgBox("Error Connecting to Database: " & ex.Message)
End Try
poojavb 29 Junior Poster
Dim myCommand As SqlCommand
myCommand = New SqlCommand("SELECT StaffCode,StaffName,Gender FROM Staff WHERE StaffCode='" & Me.txtStaffCode & "'", cnn)
Dim reader As SqlDataReader = myCommand.ExecuteReader
If reader.HasRows()
    While reader.Read
                    'txtStaffCode.Text = reader("StaffCode")
                    txtStaffName.Text = reader("StaffName")
                    cboGender.Text = reader("Gender")
    End While
Else
    MsgBox("No record found.","Not Found")
End If
reader.Close()
poojavb 29 Junior Poster

u can try the below code

Public Function GetData() As DataView
        'Open_DB_Connection()
        Dim SelectQry = "SELECT * FROM TableName"
        Dim SampleSource As New DataSet
        Dim TableView As DataView
        Try
            Dim SampleCommand As New SqlCommand()
            Dim SampleDataAdapter = New SqlDataAdapter()
            SampleCommand.CommandText = SelectQry
            SampleCommand.Connection = Connection
            SampleDataAdapter.SelectCommand = SampleCommand
            SampleDataAdapter.Fill(SampleSource)
            TableView = SampleSource.Tables(0).DefaultView
        Catch ex As Exception
            'Debug.Print("Exception: ")
            Throw ex
        End Try
        'Close_DB_Connection()
        Return TableView
End Function
poojavb 29 Junior Poster

try something like this

set the y axis of the datagridview as u want....

u can also write the below code in load as well as form resize event so that if the form is resized even the controls will be resized...

          DataGridView1.Size = New System.Drawing.Size(Me.Width / 2 - 100, 300)
          DataGridView1.Left = Me.Left + 50

          DataGridView2.Size = DataGridView1.Size
          DataGridView2.Left = Me.Width / 2 + 50

          Button1.Top = Me.Height - Button1.Height - 20
          Button1.Left = Me.Width - Button1.Width - 20
poojavb 29 Junior Poster

u can write in the textbox textchange event with the sql query using the like condition....

'Open Connection
Try
   Dim myCommand As New OleDbCommand
   With myCommand
        .CommandText = "SELECT ID , (FirstName +' '+LastName) as Name FROM TableName where  ID like '" & Textbox1.Text & "%" + "' order by ID"
        .CommandType = CommandType.Text
        .Connection = Connection
   End With
   Dim dt As New DataTable
   dt.Load(myCommand.ExecuteReader)
   With DatagridView1
        .AutoGenerateColumns = True
        .DataSource = dt
   End With
Catch ex As Exception
   MsgBox("Error in select query: " + ex.Message)
End Try
'Close Connection
poojavb 29 Junior Poster

Login form is different and user registration is different

Login form-
Create a form with the basic requirements like
two labels as username and password....
two textboxes for entering username and password
three buttons for login, closing form and one for reset....

Make the database connection....
Validate if the user is there in database and then login else error msg box

User Registration-
First make sure of the requirements of the user like firstname, lastname, email, username, password, confirm password....

Validation for email, check username if already in database, strong password if required....

creating new users....
database connection insert query

deleting users....
database connection
delete user according to username....

poojavb 29 Junior Poster

Just an idea...

I had to save the data as INP1 - first 3 characters and last integer

We cant save the alphanumeric as integer

but what I had done was....I had one temp table....which had the integer value...
every time I need to increment the value I used to check the value in that table and update in my new table....that had datatype as varchar...so everytime it used to get incremented correctly....after the insert statement then update the temp table by 1....

poojavb 29 Junior Poster

To take back up in .bak extension file
1. Right click on ur database name
2. Tasks -> back up -> Set the backup location and then click on OK.

To restore the .bak extension file
1. Right click on ur database name
2. Tasks ->Restore -> Database
3. Set the database name if the textbox is empty
4. Source for restore -> From database / from device
5. if from device...select the radio button and then click on browse
6. Click on Add -> then select the .bak file from ur correct path
7. Clck OK
8. Select the check box of the appropriate database from the list and click OK.

if u want to add the same in code...then do the following

Try
   If Not Directory.Exists("D:\Backup") Then
      Directory.CreateDirectory("D:\Backup")
   End If
   Dim MySQL_Connection As SqlConnection = New SqlConnection()
   MySQL_Connection.ConnectionString = "Data Source = LocalHost;Initial Catalog = Datasourcename;Integrated Security  = True"
   MySQL_Connection.Open()
   Dim myCommand As SqlCommand
   myCommand = New SqlCommand(" BACKUP DATABASE [Datasourcename] TO  DISK = N'D:\Backup\Datasourcename_full.bak' WITH FORMAT ", MySQL_Connection)
   myCommand.ExecuteNonQuery()
   myCommand = New SqlCommand(" BACKUP DATABASE [Datasourcename] TO  DISK = N'D:\Backup\Datasourcename_diff.bak' WITH DIFFERENTIAL ,FORMAT ", MySQL_Connection)
   myCommand.ExecuteNonQuery()
   MySQL_Connection.Close()
Catch ex As Exception
   Msgbox(ex.message)                      
End Try

Actually I dont know about the other two formats....

poojavb 29 Junior Poster

Just a guess...
ur select query does not have single inverted comma...

sql = "Select * from SRuser where Uname = '" & name & "'"
Goomba79 commented: Good help many thanks!!! +0
poojavb 29 Junior Poster

What is ur program actually doing??? what is present in the csv file??

poojavb 29 Junior Poster

Actually My controls were not getting adjust if my form changes it size....and also I wanted my form to be according to the size of users screen

I set my form windows state to maximum so that it will be maximized for all users in their system

the controls will adjust as the form resizes .....the controls which are to the left will stay to the extreme left...

In my case...
In my form I used 4 panels...
panel1 - dock top
panel2 - dock left
panel3 - dock middle
panel4 - dock right

this when I will resize the form the panel stays at their positions...so we can include the controls in their panel and check...

poojavb 29 Junior Poster

call this code on ur button click to display ur records in datagridview

'open connection
Try
   Dim myCommand As New OleDbCommand
   With myCommand
        .CommandText = "SELECT * FROM tablename"
        .CommandType = CommandType.Text
        .Connection = Connection
   End With
   Dim dt As New DataTable
   dt.Load(myCommand.ExecuteReader)
   With DatagridView1
        .AutoGenerateColumns = True
        .DataSource = dt
   End With
Catch ex As Exception
   MsgBox("Error in select query: " + ex.Message)
End Try
'close connection
poojavb 29 Junior Poster

u can also try to first clear the combo box items before adding the values to it....

poojavb 29 Junior Poster

checkbox1 - name
checkbox2 - date

give conditions in such a way that

if checkbox1.checked = true then
'ur sql query which will show the result in datagridview
elseif checkbox2.checked = true then
'ur sql query
elseif checkbox1.checked = true and checkbox2.checked = true then
'ur sql query
else 'means if both are unchecked then display error or if u want to display all details of the table
'whatever u need
End if
M.Waqas Aslam commented: very nice one , Pooja , simple and clear. +4
poojavb 29 Junior Poster

Whatever Jim has given it works...add few more lines of code

Private Sub Button7_Click(sender As System.Object, e As System.EventArgs) Handles Button7.Click 'checked on button click
    Dim found As Boolean = InListView(ListView1, ComboBox1.Text)
    If found = True Then
        MsgBox("Exists")
    Else
        'MsgBox("No")
        ListView1.Items.Add(ComboBox1.Text)
    End If
End Sub

Private Function InListView(lvw, text) As Boolean
    For Each item As ListViewItem In lvw.items
        If item.Text = text Then Return True
    Next
    Return False
End Function
poojavb 29 Junior Poster

Not enough....be more clear and precise....

poojavb 29 Junior Poster

Please post the query in Database section....This is VB.net section

poojavb 29 Junior Poster

write below code in ur button click event
textbox2 is the field where u will enter number

  MsgBox(ConvertNum(TextBox2.Text))

Then write the below function

 Public Shared Function ConvertNum(ByVal Input As Long) As String 'Call this function passing the number you desire to be changed
        Dim output As String = Nothing
        If Input < 1000 Then
            output = FindNumber(Input) 'if its less than 1000 then just look it up
        Else
            Dim nparts() As String 'used to break the number up into 3 digit parts
            Dim n As String = Input 'string version of the number
            Dim i As Long = Input.ToString.Length 'length of the string to help break it up

            Do Until i - 3 <= 0
                n = n.Insert(i - 3, ",") 'insert commas to use as splitters
                i = i - 3 'this insures that we get the correct number of parts
            Loop
            nparts = n.Split(",") 'split the string into the array

            i = Input.ToString.Length 'return i to initial value for reuse
            Dim p As Integer = 0 'p for parts, used for finding correct suffix
            For Each s As String In nparts
                Dim x As Long = CLng(s) 'x is used to compare the part value to other values
                p = p + 1
                If p = nparts.Length Then 'if p = number of elements in the array then we need to do something different
                    If x <> 0 Then
                        If CLng(s) < 100 Then
                            output = output & " And " & …
poojavb 29 Junior Poster

U must have created a crystal report using the wizard right???

That is ur crystal report....in that now u need to compare the value with crsytal report

means

the datetimepicker1 and two are ur part of vb.net code so there shud be some parameters to compare with the crystal report...

1. Open ur crystalreport1.rpt file 'dont know ur file name...
2. On left had side u will have a Field Explorer window...Right click on Parameter Fields-> New -> create two variables as fromdate and todate with datatype String.....

after this is done u need to assign the parameter values to that of ur table column ida since that contains ur date values....

1. on center of ur crystal report right click -> Report -> Selection Formula - >Record
2. A Record Selection formula Editor window will be opened ...write the below thing according to ur requirements
3. {tablename.ida} in {?fromdate} to {?todate}

this will compare in ur crystal report....

rutuja8 commented: hey when we close the record selection formula editor the error is occruing......................i applied ur replies also bt was of no use error is popping out..........pls reply me as sun as pos +0
poojavb 29 Junior Poster

Please be more specific...

poojavb 29 Junior Poster

to display data in the datagrid use the below code and then call the method with datagridview
Note- in select query call only the fields that u want to display in your datagridview1

Public Function GetData() As DataView
        'open connection
        Dim SelectQry = "SELECT * FROM Pricelist WHERE [SECURITY] ='" & Me.cboCompany.SelectedItem & "'"
        Dim SampleSource As New DataSet
        Dim TableView As DataView
        Try
            Dim SampleCommand As New SqlCommand()
            Dim SampleDataAdapter = New SqlDataAdapter()
            SampleCommand.CommandText = SelectQry
            SampleCommand.Connection = Connection
            SampleDataAdapter.SelectCommand = SampleCommand
            SampleDataAdapter.Fill(SampleSource)
            TableView = SampleSource.Tables(0).DefaultView
        Catch ex As Exception
            Debug.Print("Exception: ")
            Throw ex
        End Try
       'close connection
        Return TableView
    End Function

and when calling datagrid write the following code like in button click or form load event...

Datagridview1.DataSource = GetData()

Hope this helps you

poojavb 29 Junior Poster

As it is a number datatype a null value wont be stored in the column....it will store 0 as null value....

change it to text and then u can save a null value....

thines01 commented: Good catch! +12
poojavb 29 Junior Poster

First declare the variables and then when u will use the select query make use of reader that will read the value and assign it to the variable

eg

Dim docid as String
Dim docfname as String
Dim doclname as String
'connection string
Try
    Dim myCommand As OleDbCommand
    myCommand = New OleDbCommand("SELECT DoctorID,FirstName,LastName FROM DoctorRegister", Connection)
    Dim reader As OleDbDataReader = myCommand.ExecuteReader
    While reader.Read
          docid = reader("DoctorID")
          docfname = reader("FirstName")
          doclname = reader("LastName")
    End While
    reader.Close()
 Catch ex As Exception
    MsgBox("Error Connecting to Database: " & ex.Message)
End Try

Hope this helps u....

poojavb 29 Junior Poster

what does the searchdatas() function do??? it is not mentioned in the code???

try to write the below code in Textbox change event rather than button click and see

open connection first

         Try

            Dim myCommand As New SqlCommand
            With myCommand
                .CommandText = "SELECT * FROM tablename where columnid like '" & Textbox2.Text & "%" + "'"
                .CommandType = CommandType.Text
                .Connection = Connection
            End With
            Dim dt As New DataTable
            dt.Load(myCommand.ExecuteReader)
            With PelangganDataGridView
                .AutoGenerateColumns = True
                .DataSource = dt
            End With
        Catch ex As Exception
            Debug.Print("Exception: ")
            Throw ex
        End Try

check this or put the code in ur button click

poojavb 29 Junior Poster

This worked fine

Dim date_now As Date
date_now = DateTime.Now
Debug.Print(date_now.ToString("yyyy/MM/dd HH:mm:ss"))
poojavb 29 Junior Poster

But shud I ask u y do u need a datatable if u can login without it???

check my below code

 Try
                Dim myCommand As OleDbCommand
                myCommand = New OleDbCommand("SELECT * FROM userlogin where UserName='" & txtUsername.Text & "' and Password='" + txtPassword.Text + "'", Connection)
                Dim reader As OleDbDataReader = myCommand.ExecuteReader
                If reader.Read = True Then
                    If String.Compare(txtUsername.Text, reader("UserName"), False) Or String.Compare(txtPassword.Text, reader("Password"), False) Then 'for case sensitivity
                        MsgBox("Incorrect Credentials")
                        txtPassword.Text = ""
                        txtUsername.Text = ""
                        txtUsername.Focus()
                    Else
                        frmMain.lblWelcome.Text = "Welcome, " + reader("DrName") 'show the main form with the User First Name
                        frmMain.Show()
                        Me.Close()
                    End If
                Else
                    MsgBox("Login Failed. Try Again")
                    txtPassword.Text = ""
                    txtUsername.Text = ""
                    txtUsername.Focus()
                End If
                    reader.Close()
            Catch ex As Exception
                MsgBox("Error Connecting to Database: " & ex.Message)
            End Try

Check if this helps u....

poojavb 29 Junior Poster

well bernardz26! there are two simple ways to perform this , one is to declare a global or public variable and just access it at any part of your prog , and second way is to call the form then the call the control , here are both ways to perform this operation ,

'declare the public variable
public mynumber as int
 'now assign the value of first textbox of form1 to it .
'use this at the text change event of the textbox
mynumber = val(textbox6.text)
'now place this code at the your form two at any event where you want to sum both values of textbox6 of form1 and textbox6 of form2
textboxResult.text = val(textbox6.text)+mynumber
'this will show the result and sum both textbox values

now there is another way to perform same operation .

'use this code where you want to sum both values
textboxResult.text= val(form1.textbox6.text)+val(textbox6.text)

this will also perform same operation , hope this will solve your prob ,if your prob is solve then please dont forget to mark this thread solve ,

Regards

we can also use the CInt instead of Val or the Integer.Parse method

Jx_Man commented: Right. Val is vb6 function. +14
poojavb 29 Junior Poster

Okay, I implemented the changes that you suggested, and VS 2010 now tells me that it is expecting an end of statement at the

combobox3.text & "'"

I don't understand what it means.....

This is the update Query with the changes in it

Query = "update Prod_DB_Completed_Board set [Stock Level] = '" & TextBox2.Text & "' where Laminate = '" & ComboBox2.Text & "'" & "and where [Board Size] = " & "'" ComboBox3.Text & "'"

No need to add the where twice

Query = "update Prod_DB_Completed_Board set [Stock Level] = '" & TextBox2.Text & "' where Laminate = '" & ComboBox2.Text & "' and  [Board Size] = '" & ComboBox3.Text & "'"

This will help u