Introduction
I have found this tool in my old folders and I feel it is good to share with you.
Ten years ago, I was working in a company for developing a web application using VisualBasic.NET.
At that time we use to write some simple JavaScript functions to reduce post back times and reduce page shaking and improve performance.
Many of team member’s faces difficulties to deal with JavaScript since they came from visual basic windows development background.
At that time, I have developed this tool as a windows application to generate JavaScript code for a specific controls Text box, check box and radio button using visual interface.
Background
JavaScript and Web development basic understanding.
Using the tool
Let us have a scenario that we need a JavaScript function to enable/disable text boxes based on user selection.
- Determine the owner control for JavaScript function.
- Control Type dropdown:
The control type dropdown list provides a listing of control types supported by this tool; the user selects the type of control that will have this method. - Control Event dropdown:
The control event dropdown list provides a listing of control events supported by this tool; the user selects the event of control that will render the method. - Control Name Textbox:
The control name Textbox; the user enters the name of control that will have the method. - Start Method Button:
The start method button; will start writing the method for the selected control. - Reset Button:
The reset button; enable the user to begin new method.
- Write VB statement for the selected control
- This step starts after pressing start method button; now you write VB statement by choosing the buttons simple statement or IF statement.
Simple Statement Dialog.
IF Statement Dialog.
- press "Generate JScript Code" to generate the java script code in the text box near it.
- Copy to the Clipboard:
Add the copied JavaScript code between HTML header tags, then add the event to the owner control as below
<head runat="server">
<title></title>
<script lang="javascript" type="text/javascript" >
function chkTest_onclick()
{
var JtxtTest1;
JtxtTest1=document.getElementById("txtTest1");
JtxtTest1.disabled=true;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:CheckBox ID="chkTest" runat="server" onclick="chkTest_onclick()" />
<asp:TextBox ID="txtTest1" runat="server"></asp:TextBox>
</div>
</form>
</body>
</html>
Using the code
I have deepened on saving the user inputs on public Arrays
Public arrCode() As String
Public arrIF() As String
Public arrIFscript() As String
Public arrScript() As String
I have generate the code by reading from array and generating a string using
StringBuilder
Public Sub ShowTheScript()
Try
Dim sb As New StringBuilder
Dim intCounter As Integer = 0
rtxtScript.ForeColor = Color.Blue
For intCounter = 0 To arrCode.Length - 1
If intCounter < arrCode.Length - 1 AndAlso arrCode(intCounter + 1) = " Then" Then
sb.Append(arrCode(intCounter))
Else
sb.Append(arrCode(intCounter))
sb.Append(Environment.NewLine)
End If
Next
sb.Append(Environment.NewLine)
sb.Append("End Sub")
rtxtScript.Text = sb.ToString
Catch ex As Exception
MsgBox(Err.Description, MsgBoxStyle.Critical, "Undefined Error")
End Try
End Sub
Points of Interest
As I mentioned earlier I developed this tool long time back and I think it will be good for visual basic beginners or it can give an idea for advance developer on how the code generating tools could work.
History
Version 1.0.