BHAILOG PROGRAMMER
  • Home
  • About Us
  • Contact Us
  • Privacy Policy
  • Disclaimer
  • Home
  • C++ PROGRAM
  • Java Program
  • VB.NET PROGRAM
  • ANDROID
  • SQL
  • Q/A
  • Books

Saturday, January 12, 2019

VB.Net - Nested If Statements

 BHAILOG     January 12, 2019     VB.NET PROGRAM     No comments   

VB.Net - Nested If Statements





It is always legal in VB.Net to nest If-Then-Else statements, which means you can use one If or ElseIf statement inside another If ElseIf statement(s).


Syntax

The syntax for a nested If statement is as follows −

If( boolean_expression 1)Then
   'Executes when the boolean expression 1 is true 
   If(boolean_expression 2)Then
         'Executes when the boolean expression 2 is true 
   End If
End If

VB.NET PROGRAM


Module Module1
   Sub Main()
      'local variable definition
      Dim a As Integer = 100
      Dim b As Integer = 200
      ' check the boolean condition   
      If (a = 100) Then
         ' if condition is true then check the following 
         If (b = 200) Then
            ' if condition is true then print the following 
            Console.WriteLine("Value of a is 100 and b is 200")
         End If
      End If
      Console.WriteLine("Exact value of a is : {0}", a)
      Console.WriteLine("Exact value of b is : {0}", b)
      Console.ReadLine()
   End Sub
End Module


When the above code is compiled and executed, it produces the following result −
Value of a is 100 and b is 200
Exact value of a is : 100
Exact value of b is : 200


If you liked the tutorial then don’t forget to comment and share!
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg

The If...Else If...Else Statement

 BHAILOG     January 12, 2019     VB.NET PROGRAM     No comments   



The If...Else If...Else Statement


An If statement can be followed by an optional Else if...Else statement, which is very useful to test various conditions using single If...Else If statement.
When using If... Else If... Else statements, there are few points to keep in mind.

  • An If can have zero or one Else's and it must come after an Else If's.
  • An If can have zero to many Else If's and they must come before the Else.
  • Once an Else if succeeds, none of the remaining Else If's or Else's will be tested.

Syntax

The syntax of an if...else if...else statement in VB.Net is as follows −
If(boolean_expression 1)Then
   ' Executes when the boolean expression 1 is true 
ElseIf( boolean_expression 2)Then
   ' Executes when the boolean expression 2 is true 
ElseIf( boolean_expression 3)Then
   ' Executes when the boolean expression 3 is true 
Else 
   ' executes when the none of the above condition is true 
End If

VB.NET PROGRAM


Module Module1
   Sub Main()
      'local variable definition '
      Dim a As Integer = 100
      ' check the boolean condition '
      If (a = 10) Then
          ' if condition is true then print the following '
          Console.WriteLine("Value of a is 10") '
      ElseIf (a = 20) Then
          'if else if condition is true '
          Console.WriteLine("Value of a is 20") '
      ElseIf (a = 30) Then
          'if else if condition is true  
          Console.WriteLine("Value of a is 30")
      Else
          'if none of the conditions is true 
          Console.WriteLine("None of the values is matching")
      End If
      Console.WriteLine("Exact value of a is: {0}", a)
      Console.ReadLine()
   End Sub
End Module


When the above code is compiled and executed, it produces the following result −
None of the values is matching
Exact value of a is: 100.







If you liked the tutorial then don’t forget to comment and share!
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg

VB.Net - If...Then...Else Statement

 BHAILOG     January 12, 2019     VB.NET PROGRAM     No comments   



VB.Net - If...Then...Else Statement



An If statement can be followed by an optional Else statement, which executes when the Boolean expression is false.

Syntax

The syntax of an If...Then... Else statement in VB.Net is as follows −

If(boolean_expression)Then
   'statement(s) will execute if the Boolean expression is true 
Else
  'statement(s) will execute if the Boolean expression is false 
End If

If the Boolean expression evaluates to true, then the if block of code will be executed, otherwise else block of code will be executed.



VB.NET PROGRAM


Module Module1
   Sub Main()
       'local variable definition '
      Dim a As Integer = 100
      ' check the boolean condition using if statement 
      If (a < 20) Then
          ' if condition is true then print the following 
          Console.WriteLine("a is less than 20")
      Else
          ' if condition is false then print the following 
          Console.WriteLine("a is not less than 20")
      End If
      Console.WriteLine("value of a is : {0}", a)
      Console.ReadLine()
   End Sub
End Module


When the above code is compiled and executed, it produces the following result −
None of the value is matching
value of a is : 100 




If you liked the tutorial then don’t forget to comment and share!
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg

VB.Net - If...Then Statement

 BHAILOG     January 12, 2019     VB.NET PROGRAM     No comments   

VB.Net - If...Then Statement




It is the simplest form of control statement, frequently used in decision making and changing the control flow of the program execution. Syntax for if-then statement is −

If condition Then 
[Statement(s)]
End If

Where, condition is a Boolean or relational condition and Statement(s) is a simple or compound statement. Example of an If-Then statement is −

If (a <= 20) Then
   c= c+1
End If

If the condition evaluates to true, then the block of code inside the If statement will be executed. If condition evaluates to false, then the first set of code after the end of the If statement (after the closing End If) will be executed.


VB.NET PROGRAM 


Module Module1
   Sub Main()
      'local variable definition 
      Dim a As Integer = 10
      ' check the boolean condition using if statement 
      If (a < 20) Then
         ' if condition is true then print the following 
         Console.WriteLine("a is less than 20")
      End If
      Console.WriteLine("value of a is : {0}", a)
      Console.ReadLine()
    End Sub
End Module


When the above code is compiled and executed, it produces the following result −

a is less than 20
value of a is : 10





If you liked the tutorial then don’t forget to comment and share!
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg

My First Java Program: Print a Message "Welcome Program"

 BHAILOG     January 12, 2019     JAVA PROGRAM     No comments   

 JAVA PROGRAM 



public class Welcome
{
  public static void main(String args[])
   {
      System.out.println(“Welcome to java program”);
   }
}



If you liked the tutorial then don’t forget to comment and share!
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg

Sunday, January 6, 2019

How to Make a Tic-Tac-Toe Game for Android

 BHAILOG     January 06, 2019     Android     No comments   

Hello everyone, in this tutorial we are going to learn how to make a Tic-Tac-Toe Game for android (using Android studio). Step by step process is given in this article that will help you to make a simple Tic-Tac-Toe game in very easy way.

You can also download the apk file and use it as a normal app in your android phone.

Steps to Make a Tic-Tac-Toe Game App for Android

1. First of all open android studio

2. Create a new project > Start a new Android Studio Project > Now name your project “Tic-Tac-Toe”.



3. Choose a Package Name. A Package Name is a unique URL of your Application. In most cases it is the inverse of your website. For example: mohit.bhailogprogrammer.com

4. If you want you can leave it to the default package name which is “mohit.tictactoe.com”. Now hit next two times.


5. If you have made an Icon then add it otherwise go with the default one. Select Empty Activity > Now name your activity


6. After entered application name, it going to be called select the form factors your application runs     on, here need to specify Minimum SDK, in our tutorial, I have declared as API15:Android   4.0.3(IceCreamSandwich) −


7. After completing this go to Package Explorer & under your Package Explorer Select src > Your package Name > activity_main.xml


8. Open the activity_main.xml file and paste the given code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context=".MainActivity"> <RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content"> <TextView android:id="@+id/text_view_p1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="player 1: 0" android:textSize="30sp" android:freezesText="true"/> <TextView android:id="@+id/text_view_p2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/text_view_p1" android:text="player 2: 0" android:textSize="30sp" android:freezesText="true"/> <Button android:id="@+id/button_reset" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_alignParentEnd="true" android:layout_alignParentRight="true" android:layout_marginTop="22dp" android:layout_marginEnd="47dp" android:layout_marginRight="47dp" android:text="reset" /> </RelativeLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1"> <Button android:id="@+id/button_00" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:textSize="60sp" android:freezesText="true"/> <Button android:id="@+id/button_01" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:textSize="60sp" android:freezesText="true"/> <Button android:id="@+id/button_02" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:textSize="60sp" android:freezesText="true"/> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1"> <Button android:id="@+id/button_10" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:textSize="60sp" android:freezesText="true"/> <Button android:id="@+id/button_11" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:textSize="60sp" android:freezesText="true"/> <Button android:id="@+id/button_12" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:textSize="60sp" android:freezesText="true"/> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1"> <Button android:id="@+id/button_20" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:textSize="60sp" android:freezesText="true"/> <Button android:id="@+id/button_21" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:textSize="60sp" android:freezesText="true"/> <Button android:id="@+id/button_22" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:textSize="60sp" android:freezesText="true"/> </LinearLayout> </LinearLayout>
9. After completing this go to Package Explorer & under your Package Explorer Select src > Your package Name > MainActivity.java


10. Open the MainActivity.java file and paste the given code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
package com.example.mohit.tictactoexo; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.TextView; import android.widget.Toast; import java.util.concurrent.atomic.AtomicReference; import static android.icu.lang.UCharacter.GraphemeClusterBreak.V; public class MainActivity extends AppCompatActivity implements OnClickListener { private Button[][] buttons = new Button[3][3]; private boolean player1Turn = true; private int roundCount; private int player1Points; private int Player2Points; private TextView textViewPlayer1; private TextView textViewPlayer2; private int player2Points; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); textViewPlayer1 = findViewById(R.id.text_view_p1); textViewPlayer2 = findViewById(R.id.text_view_p2 ); for (int i = 0; i < 3; i++){ for (int j = 0; j < 3; j++){ String buttonID = "button_" + i + j; AtomicReference<String> defType; int resID = getResources() .getIdentifier(buttonID, defType.get()"id", getPackageName()); buttons[i][j] = findViewById(resID); buttons[i][j].setOnClickListener(this); } } Button buttonReset = findViewById(R.id.button_reset); buttonReset.setOnClickListener(new View.OnClickListener()){ @Override public void onClick(View V){ resetGame(); } }); } @Override public void onClick(View v){ if (!((Button)v).getText().toString().equals("")){ return; } if (player1Turn){ ((Button)v).setText("X"); } else { ((Button)v).setText("O"); } roundCount++; if (checkForWin()){ if (player1Turn){ player1Wins(); } else { player2Wins(); } } else if (roundCount == 9){ draw(); } else { player1Turn = !player1Turn; } } private boolean checkForWin(){ String[][] field = new String[3][3]; for (int i = 0; i < 3; i++){ for (int j = 0; j < 3; j++){ field[i][j] = buttons[i][j].getText().toString(); } } for (int i = 0; i < 3; i++){ if (field[i][0].equals(field[i][1]) && field[i][0].equals(field[i][2]) && !field[i][0].equals("")){ return true; } } for (int i = 0; i < 3; i++){ if (field[0][i].equals(field[1][i]) && field[0][i].equals(field[2][i]) && !field[0][i].equals("")){ return true; } } if (field[0][0].equals(field[1][1]) && field[0][0].equals(field[2][2]) && !field[0][0].equals("")){ return true; } if (field[0][2].equals(field[1][1]) && field[0][2].equals(field[2][0]) && !field[0][2].equals("")){ return true; } return false; } private void player1Wins() { player1Points++; Toast.makeText(this, "Player 1 wins!", Toast.LENGTH_SHORT).show(); updatePointsText(); resetBoard(); } private void player2Wins() { player2Points++; Toast.makeText(this, "Player 2 wins!", Toast.LENGTH_SHORT).show(); updatePointsText(); resetBoard(); } private void draw() { Toast.makeText(this,"Draw!", Toast.LENGTH_SHORT).show(); resetBoard(); } private void updatePointsText(){ textViewPlayer1.setText("player 1: " + player1Points); textViewPlayer2.setText("player 2: " + player2Points); } private void resetBoard(){ for (int i = 0; i < 3; i++){ for (int j = 0; j < 3; j++){ buttons[i][j].setText(""); } } roundCount = 0; player1Turn = true; } private void resetGame(){ player1Points = 0; player2Points = 0; updatePointsText(); resetBoard(); } @Override protected void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); outState.putInt("roundCount", roundCount); outState.putInt("player1Points", player1Points); outState.putInt("player2Points", player2Points); outState.putBoolean("player1Turn", player1Turn); } @Override protected void onRestoreInstanceState(Bundle savedInstanceState) { super.onRestoreInstanceState(savedInstanceState); roundCount = savedInstanceState.getInt("roundCount"); player1Points = savedInstanceState.getInt("player1Points"); player2Points = savedInstanceState.getInt("player2Points"); player1Turn = savedInstanceState.getBoolean("player1Turn"); } }


11.Select build Android Application and build apk

Show your apk



If you liked the tutorial then don’t forget to comment and share!
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg
Newer Posts Older Posts Home

Popular

  • WINTER – 2018 EXAMINATION
    WINTER – 2018 EXAMINATION
    WINTER – 2018 EXAMINATION  MODEL ANSWER MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION DOWNLOAD PDF Information Technology Department...
  • VB.Net program
    VB.Net program
    VB.Net PROGRAM VB.Net Hello World Example Let us look at a simple code that would print the words "Hello World" − I...

Translate

About Me

indian-choice
View my complete profile

Followers

  • Home
  • C++ PROGRAM
  • Java Program
  • VB.NET PROGRAM
  • ANDROID
  • SQL
  • Q&A
  • Books

BLOG

  • About Us
  • Disclaimer
  • Privacy Policy
  • Contact Us

Copyright © BHAILOG PROGRAMMER | Powered by Bhailog Programmer
Design by Mohit and Pravin