Thursday, September 29, 2016

HOW TO IMPLEMENT A LOGIN FORM IN VB6

Before anything else, I will assume that you have previous knowledge with regards to constructing basic SQL commands using MS Access. This tutorial will demonstrate how to create a login form in Visual Basic 6.0 using MS Access as database engine.

To get us started, we need to create a new table to our database. Name it ‘Users’, with the following structure:
FIELD NAME
DATA TYPE
ATTRIBUTES
ID
AutoNumber

Username
Text
Field Size: 15
Password
Text
Field Size: 255 | Input Mask:*

The structure is pretty straight forward. The ID field is Auto Incremented and will serve as the Primary Key. The Username is of type Text with the length of 15 characters long. Finally, the Password field 255 in length.

It is time to populate the table. We are going to start with two users only for this tutorial. Insert the following records:
ID
Username
Password
1
alex
Kulot01@
2
john
Whitewolf69

Now our table is ready. We only have two authorized login credentials which of Alex and John with their corresponding password.

Next, we will design our login form in VB6 IDE. Create a form with similar objects in it as shown below:


Form Layout

Control
Property
Value
Form
Name
Caption
BorderStyle
Height
Width
Form1
Login
1 – Fixed Single
3135
4845
Label1
Caption
User:
Label2
Caption
Password:
Text1
Name
Text
txtUser
Text2
Name
Text
PasswordChar
txtPassword

*
Command1
Name
Caption
cmdCancel
Cancel
Command2
Name
Caption
cmdLogin
Login
Controls, Properties and Values Matrix

Source Code
Form1.frm

Option Explicit

Private Sub cmdCancel_Click()   
    Unload Me
End Sub

Private Sub cmdLogin_Click()
    Dim rs As New Recordset
    Dim user As String
    Dim password As String
    Dim sql As String
   
    user = txtUser.Text
    password = txtPassword.Text
   
    sql = "SELECT * FROM Users WHERE Username = '" & user & "'"
    Debug.Print sql
    rs.Open sql, con, adOpenDynamic, adLockOptimistic
   
   
    If rs.State Then
        While Not rs.EOF
            If rs!password = password Then
                   
                'Load your main form because the access has been authorized
                Unload Me
                Exit Sub
            End If
           
            rs.MoveNext
        Wend
    End If
   
    MsgBox "Invalid Username or Password!", vbExclamation, "Authentication"
   
    rs.Close
    Set rs = Nothing
End Sub


NOTE: Upon running the application, the first form to load should be the Login form.

Wednesday, September 28, 2016

Test Case #1 - HINT

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.Scanner;

public class fileinput {
public static void main(String[] args) throws IOException {
BufferedReader br = null;
String sCurrentLine;
String emp[];
Scanner input=new Scanner(System.in);
String id;
boolean flag=false;
int position;
String position_desc="";
Double daily_rate=0.0;

System.out.print("Enter Code: ");
id=input.nextLine();

br = new BufferedReader(new FileReader("C:\\Users\\home\\Documents\\employees.txt"));

while ((sCurrentLine = br.readLine()) != null) {
emp=sCurrentLine.split(",");

if ( id.equals(emp[0])  ){

position=  Integer.parseInt( emp[2] );
if (position==1){
position_desc="Manager";
daily_rate=650.0;
}else if(position == 2){
position_desc="Supervisor";
daily_rate=550.0;
}else if(position == 3){
position_desc="Messenger";
daily_rate=500.0;
}

System.out.println( "Name: " + emp[1]);
System.out.println( "Position: " + position_desc);
System.out.println( "Daily Rate: " + daily_rate);

flag=true;


}

}

if (flag==false ) System.out.println("Employee not found!");


}

}

Thursday, September 22, 2016

Processing Delimited String


public class Parse {

    public static void main(String [] args) {
    String arr[];
    String str="E006,Herbert Colanggo,3";
   
    arr=str.split(",");
   
   
   
   
    System.out.println(arr[0]);
    System.out.println(arr[1]);
    }
    
    
}

How To Read A Text File in Java




import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;

public class fileinput {
public static void main(String[] args) throws IOException {
BufferedReader br = null;
String sCurrentLine;

br = new BufferedReader(new FileReader("C:\\Users\\home\\Documents\\Db.txt"));
while ((sCurrentLine = br.readLine()) != null) {
System.out.println(sCurrentLine);
}

}

}

Wednesday, September 21, 2016

TEST CASE 1 - Compro6

Download the files below:

  1. compro6-endterm-project-testcase1.docx
  2. employees.txt

How to compute hour interval between two times? Click here!

How to compute the number of hours between two given times in Java

/**
 * @(#)testcase1.java
 *
 *
 * @author : A. Dichosa
 * @version 1.00 2016/9/21
 */


public class testcase1 {
    public static void main(String [] args) {
    String timein,timeout;
    double time_interval=0; 
        
    timein="8:00";
    timeout="12:00";
    time_interval=GetHourInterval(timein,timeout);
       

    System.out.println(String.format("%.2f",time_interval));    
    }   
    
    /*
     *Description: This method computes the hour interval between two times. It takes two parametes in and out.
     */
    private static double GetHourInterval(String in, String out){
    String timein_arr[];
    String timeout_arr[];
   
    double in_hours=0;
    double out_hours=0;
    double total_hours=0;
   
    timein_arr=in.split(":");
    timeout_arr=out.split(":");
   
    in_hours=Double.parseDouble( timein_arr[0])+ (Double.parseDouble(timein_arr[1])/60);
    out_hours=Double.parseDouble( timeout_arr[0])+ (Double.parseDouble(timeout_arr[1])/60);
    total_hours=out_hours-in_hours;
   
    return total_hours;
   
    }
    
}

Thursday, September 15, 2016

A Simple CRUD using Laravel 5.2 Framework

Steps to Install the Application to a Remote Server
  1. Decompress and upload all files to target directory gregorytest.rar.
  2. Import the database gregorydata.sql
  3. Copy all files inside /public folder into the default project folder.
  4. Remove folder /public.
  5. Edit file ./index.php, add this line
    use Illuminate\Contracts\Http\Kernel; to the topmost line.
    On the same file, look for line
    require __DIR__.'/../bootstrap/autoload.php';
    and replace it with
    require __DIR__."/bootstrap/autoload.php";
    Also, line
    $app = require_once __DIR__.'/../bootstrap/app.php';
    with
    $app = require_once __DIR__."/bootstrap/app.php";
    Lastly line $kernel = $app->make(Illuminate\Contracts\Http\Kernel::class);
    with
    $kernel = $app->make(Kernel::class);
  6. Edit file /config/bootstrap.php and locate line 'url' => env('APP_URL', 'http://localhost'), and replace it with 'url' => env('APP_URL', 'http://[you_project_folder]/'),
  7. Finally, .env file needs editing also
    APP_ENV=local
    APP_DEBUG=true
    APP_KEY=base64:eegf6eODvThzJiyXWMp3Bh7OLUbgqOJhQ16kZcXr9qw=
    APP_URL=http://[project_directory]
    DB_CONNECTION=mysql
    DB_HOST=sql6.freemysqlhosting.net
    DB_PORT=3306
    DB_DATABASE=sql6135311
    DB_USERNAME=sql6135311
    DB_PASSWORD=3te5D9vhTU
  8. Enjoy!