Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need a jump start

Status
Not open for further replies.

Catrina

Programmer
Feb 11, 2000
70
US
I am just learning VB (actually programming period), using books and help from a DOS programmer. I am currently converting an old DOS payroll program to windows using VB 6.0. Up until now I have been using text boxes to gather input such as deduction titles, totals etc. I have been<br>using the KeyPress event on the textboxes, to set the input into the files, then set focus to the next text box after the user hits enter (I am trying to make the program, as much as possible, work like the old DOS version). This is how I've been doing it. This example happens to be where I am setting the edit masks, I will be using to hide various<br>textboxes (problem below). <br><br>Private Sub txtDbl_KeyPress(KeyAscii As Integer) <br>KeyAscii = Asc(UCase(Chr(KeyAscii))) <br>ZOUT$ = Chr(KeyAscii) <br><br>If KeyAscii = 13 Then <br>KeyAscii = 0 <br>ZOUT$ = Mid(OP.VOID2EDIT, 8, 1) <br>txtDbl.Text = ZOUT$ <br>End If <br><br>If ZOUT$ = &quot;+&quot; Or ZOUT$ = &quot;-&quot; Or ZOUT$ = &quot; &quot; Then <br>KeyAscii = 0 <br>Mid(OP.VOID2EDIT, 8, 1) = ZOUT$ <br>txtDbl.Text = ZOUT$ <br>Else <br>Invalid 'Invalid entry routine <br>txtDbl.Text = &quot;&quot; <br>txtDbl.SetFocus <br>Exit Sub <br>End If <br><br>cmdFinishVoid.SetFocus <br>End Sub <br><br>I have now come to a part that I'm not sure how to go about. I have a form with several textboxes used for entering cash pay totals. These boxes are not visible if an edit mask is set. What I need to do is check to see if the edit mask is set (&quot;-&quot;) in a file (OP.VoidEdit, etc) if it<br>is, I want to skip that text box and leave it hidden. Then check the next one, once one is found that needs to be displayed, I want to display it, take the input, then continue on with the mask check until I find the next needed textbox. I'm not sure how to go about coding this.<br>Just a start would be very helpful. It can be done either with the non-edited boxes showing right from the beginning, and as the user hits enter, the focus goes to the next visible box, or the non-edited boxes appear one by one as the users enters the data (this is how the original<br>DOS program works). I hope this makes since. The only way I can think of doing it would take tons of coding, and maybe that is what I will have to do, but hopefully you will have an idea to help. <br><br>Thanks in advance <br><br>Catrina
 
If only the world was like that; with everyone still using <b>DOS</b>, screens and user input being a major consideration with every application. But wait, this hasn't been the case since Windows 3.0! A major part of the Windows API back then was the <i><u>event model</u></i>. <br><br>Today, using Access to create world class applications, The VBA event model is a major consideration in how we design programs. <br><br>&quot;Way back when&quot;. A 'Keyboard Handler' was always a critical part of the program. No More.<br><br>Take some time out to explore the VBA 'Event Model' (in MS Access). It can be cumbersome and imposing at times, but we (eventually) learn that it is our friend.<br><br><u>Gone</u> are the days where we process 'keystrokes''.<br><br><br>Have fun !<br> <p>Amiel<br><a href=mailto:amielzz@netscape.net>amielzz@netscape.net</a><br><a href= > </a><br>
 
Amiel,<br><br>With respect - processing key-strokes to check user-input is perfectly valid.<br><br>Catrina,<br><br>Could you write a function called something like this?<br><br>ShouldTextBoxBeVisible(TextBoxControl)<br><br>The function should return True if the TB has an edit mask and False if it doesn't.<br><br>You could then say something like:<br><br>txtAnotherTextBox.Visible = ShouldTextBoxBeVisible(txtAnotherTextBox)<br><br><br> <p>Mike<br><a href=mailto:michael.j.lacey@ntlworld.com>michael.j.lacey@ntlworld.com</a><br><a href= Cargill's Corporate Web Site</a><br>
 
Catrina, I think Amiel is 'suggesting' that you explore other avanues of processing, such as &quot;lost focus&quot; to validate the user input, not to do it keystroke by keystroke.&nbsp;&nbsp;Also for your checking the availability of a specific control, I have found that using the enabled property is less distracting (to the user) than manipulating the visible property.&nbsp;&nbsp;To do the actual set-up of the individual boxes, it is not clear what condition(s) determine the 'availability' of the text boxes.&nbsp;&nbsp;If - in general - each text box would depend on actions taken within the form/screen, then processing the conditional block will just have to take place at the &quot;completion&quot; of the entry for each text box.&nbsp;&nbsp;On the otherhand, if the criteria are known at &quot;form activation&quot;, then the entire logic could be processed in that event, including setting the tab order (if necessary), so that the user needs to ONLY do the data entry - using the tab key to move between fields.<br>
 
<br>...exactly what was intended Catrina, and thank's for understanding and clarifying my remarks Mike. <p>Amiel<br><a href=mailto:amielzz@netscape.net>amielzz@netscape.net</a><br><a href= > </a><br>
 
I see a few things here,<br><br>1) you want real time data validation to eliminate the need for annoying popups.<br>2) you want an easy way to specilaize your edit boxes according to templates.<br><br>Things to learn about:<br><br>A) Windows API and the APIViewer application.&nbsp;&nbsp;Your solution crys out for the GetPrivateProfile family of methods.<br><br>This family of API calls allows you to create a virtual database in its simplest form.&nbsp;&nbsp;<br><br>B) Control arrays.&nbsp;&nbsp;These reduce redundant code, the trick is to identify what becomes a property of the group.&nbsp;&nbsp;Besides reducing the coding effort using an array adds a few tools to your box.&nbsp;&nbsp;The for loop is one of basics staple statements, second only to the if statement.<br><br>C) String manipulations, VB6 opened the door for some really radical methods.&nbsp;&nbsp;The split method is a killer method eliminating the need for a parser.&nbsp;&nbsp;This allows you to parse the string from the ini file into an array that actually adds properties to your control.&nbsp;&nbsp;Lets say for example, Navigation properties Next and Previous.&nbsp;&nbsp;A validation string providing valid keys or some flag identifying a validation method, a visible flag, and just about anything you acan think of.<br><br>D) Your problem definition screams user control, but that's just a little out of reach of a novice programmer.&nbsp;&nbsp;I urge you to extend, but can't do the pushing yet. <br><br>Tying all this together, <br><br>You end up with an INI file containing sections which represent your templates. <br>These sections contain numbered values, like edit01 and edit02, containing information needed to specialize your controls. For example:<br><br>[Template01]<br>form=Visible¦Previous¦Next¦Valids¦Message<br>edit01=1¦-2¦3¦1234567890¦Please use only numbers<br>edit02=0¦¦¦¦<br>edit03=1¦1¦-1¦ALL¦How did you enter bad data?<br><br>A loop helps initialize controls based on the data, I like to cache it into the tag property.<br><br>GetPrivateProfileString gets the data for you. I'll leave the research to you.<br><br>Split parses the strings into an array making them easier to use.<br>Params=Split(INIDataString, &quot;¦&quot;)<br>or Params=Split(myControl(index).Tag, &quot;¦&quot;)<br><br>I like 0 based arrays,&nbsp;&nbsp;<br>Params(0) tells you if the control is visible, and if there's anything else worth looking at.<br>VAL(Params(1)) and VAL(Params(2)) give you navigation indexes previous and next, check for sentinals.<br>(0 &lt; instr(str(keyascii), PARAMS(3)) tells you if you got a good key, of course again there are special conciderations for values like ALL or ALPHA.<br><br>You can loop thru the array to determine form completeness.<br><br>Other ideas should start sparking soon.<br>
 
How about ...<br><br>Private Sub Text1_OnExit()<br>&nbsp;&nbsp;dim pos as integer<br>&nbsp;&nbsp;if pos = InStr([text1],&quot;-&quot;) then<br>&nbsp;&nbsp;&nbsp;&nbsp;[text3].SetFocus ' Skipp over text2<br>&nbsp;&nbsp;end If <br>end If<br><br>or ...<br><br>Private Sub Text2_OnExit()<br>&nbsp;&nbsp;dim pos as integer<br>&nbsp;&nbsp;&nbsp;if pos = InStr([text2],&quot;-&quot;) then&nbsp;&nbsp;&nbsp;<b>'dash at pos 3?</b><br>&nbsp;&nbsp;&nbsp;&nbsp;if pos = 3 then<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if Instr(pos, [Text2],&quot;-&quot;) = 0 then <b>' second dash also? </b><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[text5].SetFocus ' Skipp over text3 <u>and</u> text4<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end if<br>&nbsp;&nbsp;&nbsp;&nbsp;end if<br>&nbsp;&nbsp;end If <br>end sub<br><br>Nothing will pop up, also nothing will blink on and off on the form. And it can be done with a couple of mouse clicks and about a dozen lines of (U) added code. <br><br>If you just <i>want</i> to make the program work like DOS programs used to, you will likely be able to accomplish that, <b>and</b> have a working program too ... but, <i>why</i>? <br><br><i>Real time validation</i>(?) probably means validating the data before it gets stored away somewhere. (same as the regular kind of validation i'd imagine).<br><br>But really, no matter what a user enters on a form it won't be stored away until some code somewhere in the app calls &quot;Add&quot; or &quot;Update&quot; or &quot;Delete&quot;, &quot;Save&quot;, &quot;Write&quot;, or whatever.<br><br>Which means. Hey, no need to create buffers to store strings, the strings are already in buffers! No special memory requirements (alredy taken care of). No need for external function libraries (VB is sufficent for this basic type of task). Every time a user does something an &quot;Event Procedure&quot; executes you can then use these 'Events' to carry out tasks in the background (kinda like DOS interrupts(?)), stuff like data validations.<br><br>VB is a RAD (Rapid App. Development) tool. It makes routine tasks (like data validation) very quick and simple to accomplish, however, Im sure it was never intended to be made to work like DOS&nbsp;&nbsp;vs. being allowed to work like Visual Basic.<br><br>And so whats left? Well, do what we all ended up doing, take some time to learn about Visual Basic, and then re-build your form so it'll work. <p>Amiel<br><a href=mailto:amielzz@netscape.net>amielzz@netscape.net</a><br><a href= > </a><br>
 
Thanks everyone, I've worked out the problem. In the form load, I checked for the edited out textboxes, if they are edited, their background color is the same as the form. This way I set a routine to check if the next text box has that color, if so, it is skipped. Probably a elementary way of doing it, but I also needed the user to be able to click on an edited box to use it if needed, this way the user can see the box and go to it if needed, but doesn't stop on it if it is not needed.<br><br>I know I am not taking full advantage of VB, but I have to do the program like the boss wants, and he is a die hard DOS programmer. Thats why I am the one learning VB.<br><br>Catrina
 
<br><br>&nbsp;&nbsp;&nbsp;<i>Sounds like a solution to me</i>!<br><br>: ) <p>Amiel<br><a href=mailto:amielzz@netscape.net>amielzz@netscape.net</a><br><a href= > </a><br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top