How would I go about preventing the user from going into nonexistent records in a database (Visual basic 6.0 using Microsoft DAO 2.5/3.51) - vb6

Firstly, I am using visual basic 6 because that is what my school teaches.
We are meant to do a practice project for a supposed client that wants a program that allows employees to interact with a database.
I have made the First, prev,next and last button for record navigation, however, the issue is that the user is allowed beyond existing records using prev or next and it crashes the program with the error that there is no value
I have tried things like:
Making 2 counters, one for the current record that you are on and one for how many records are in the selected recordset. What I thought it would do is that if your current record tries to surpass the recordcount, it will cancel the action, but in the end the recordset.recordcount always returned 1 or 0 for some reason
I have also tried testing for if the primary key field is blank, but it returns the error that there is no such record
So how would I go about limiting the user from going beyond the records?

In the end, I was able to use an error handler for my problem to handle the error of the user trying to go beyond existing records.
What I did was:
On Error GoTo ErrHandler 'If any error happens go to ErrHandler
recordset.movenext
setFields 'Subroutine for setting the text boxes to their values
ErrHandler:
recordset.movelast 'If the user tries to go beyond the last record move him back
Update 2: I have also tried using the BOF and EOF people have been saying in the comments. I first had some confusion regarding them because I thought these properties were checking if it was the first record or the last record, but actually it was checking if you were outside of the file.
recordset.movenext 'move to the next record
If recordset.EOF = True Then 'If the user is outside the file
recordset.moveprevious 'Move him back
Else 'If he is not
setFields 'Set the fields
End If 'End the if
This is much simpler than the error handler.

Related

Where is the best place to store an application setting that needs to be updated frequently in ServiceNow

I have a scheduled script execution that needs to persist a value between runs. It is updated with each run. Using gs.setProperty seemed like the natural place until I came across this:
Care should be taken when setting system properties (sys_properties)
using this method as it causes a system-wide cache flush. Each flush
can cause system degradation while the caches rebuild. If a value must
be updated often, it should not be stored as a system property. In
general, you should only place values in the sys_properties table that
do not frequently change.
Creating a separate table to store a single scalar value seems like overkill. Is there a better place to store it?
You could set a preference if you need it in the instance. Another place could be the events table. Log the event with the data in parm1 or parm2 and on next run query the most recent event.
I'd avoid making a table as that has cost implications for some clients. I agree with the sys_properties.
var encrypter = new GlideEncrypter();
var encrypted = encrypter.encrypt('Super Secret Phrase');
gs.info('encrypted: ' + encrypted);
var decrypted = encrypter.decrypt(encrypted);
gs.info('decrypted: ' + decrypted);
/**
*** Script: encrypted: g/bXLJHa7xNRMKZEo5q/YtLMEdse36ED
*** Script: decrypted: Super Secret Phrase
*/
This way only administrators could really read this data. Also if I recall correctly, the sysevent table is cleared after 7 days. You could have the job remove the event as soon as it has it in memory.

Upload a single file with FineUploader in basic mode, error after second upload

I am working on allowing only a single file to be uploaded via FineUploader in basic (Non-UI mode). I have set the 'itemLimit: 1' inside the validation options. This works fine and I see the error message: "Too many items (3) would be uploaded. Item limit is 1." if I select 3 files instead 1 file.
Now, when I select 1 file, and upload it, I click the upload button again and try to select 3 files again, but this time it says "Too many items (4) would be uploaded. Item limit is 1." even though I have selected only 3 files. So, now if I select only 1 file, it gives me an error saying: "Too many items (2) would be uploaded. Item limit is 1." even though only 1 file was selected. Is this a bug?
I guess what I am really asking, is, how do I make FineUploader accept only 1 file for upload at any given time when FineUploader instance has been constructed in basic (non-UI) mode?
Thanks.
I'm fairly certain that I already answered this concept in a very similar question:
In the case of itemLimit, the "session" is simply the current
instance of Fine Uploader. To start a new "session", you would
construct a new instance of that Fine Uploader object, either by a
page refresh or programmatically.

Visual Basic: How to use timer properly

I'm trying to write a simple program that could perform some tasks at specified time.
Here's what I have:
If (TimeOfDay = "06:12:50") Then
MsgBox(TimeOfDay)
End If
If (TimeOfDay = "06:13:58") Then
MsgBox(TimeOfDay)
End If
This code is placed inside Timer1_Tick, I set time interval - 1000 and it works OK, I get TimeOfDay value in MsgBox when current time is equal to my specified time.
But what should I do to make it work dynamically? For example: I want to type TIME value via TextBox and pass it to Timer1_Tick I need to do it as many times as I want so everytime current time matches with my specified hour,minute,second it would work, but I don't know where I have to put my code, because if I place code in while loop and in Time_Ticker1 it runs while loop every second and UI crashes immediately.
Thank you in advance for your help!
Have you considered setting a Windows Scheduled event of MSG to yourself using the AT command line? The operating system timer/scheduler, dialog, storage and queue are already there and the MSG can optionally be dismissed if there is no one to receive it within a set amount of time. Example to send the time at 06:12:15 run the following into a command shell.
AT 06:12:15 msg %USERNAME% It is 06:12:15 am

VBScript: Reminder for office workers and personal use

My program asks the user for any events that he will be having later on (eg. meeting/special lunch event/submit report/pay bills/birthday) and will remind the user when the time comes.
Here is my code:
Dim remind
re=MsgBox("Do you want me to remind you anything later on?", vbYesNo, "Reminder")
If re=6 then call main
Sub main
' Ask for the time that the user wanted to be reminded
remind=InputBox("At what time?" & vbNewLine &
"Please use this format {H:MM:SS AM/PM}" & vbNewLine &
"Note: H is in 12h format")
' Description eg. "Lunch with boss"
reminder=InputBox("Any discription you want to add in?")
Do Until check=remind
check=Time
If check=remind Then MsgBox reminder
Loop
End Sub
For example, I put in 12:30:00 PM and Lunch with boss. Even when the time comes nothing happens, no popup. And when I check my TaskManager it is still running.
I'm using wscript.exe to run this script. It's the do until check=remind part that doesn't work. If I put do until check="12:30:00 PM" then it will work.
PS: I know we can use the Microsoft Outlook for the reminder or even use our phones. But this is well suited for workers that are 24h infront of the computer and lazy to use their phones and update their outlook.
Convert to Date data type
The issue seems to be that the remind variable is a String data type, and the check variable is a Date data type. When you try to compare them, they'll always fail to be equal, even if the actual date inside both types is the same.
You can solve the problem by using the CDate function to convert remind to a Date before entering the loop.
remind = CDate(remind)
Validation
Because you're now using CDate to convert the user's input, if they make a typo and enter an invalid date, its going to bring up an error box and end the program. You may want to use IsDate to ensure it is a valid time before converting it, then gracefully ask the user to enter the time again if they made a typo.
CPU Usage
Your loop will sit there taking up 100% CPU usage of one core of the machine its running on. This can slow down your user's computer, among other side effects.
To fix this issue, you want to slow down the loop, such that its only checking a few times a second, rather than a few hundred times a second. Insert this statement inside the loop to have it sleep for 500 milliseconds before trying again.
WScript.Sleep 500

Troubleshooting HBase batch puts

Is it possible to troubleshoot HBase batch puts? I'm using HBase batch puts of 5000 records at a time, and I would like to, on put failure, find out which row or rows is causing a problem and to log it.
The method HTable.batch(List actions) receives a list of Puts and returns an array in the same size of actions list (your puts list you gave to the function). If actions(i) failed, then the result[i] will be null.
Please note that when the failure inside batch() is due to maximum number of attempts to write, you need to catch RetriesExhaustedWithDetailsException, and call getExceptions(), to get the array which contains the mapping of the error to the put causing it.
See code here

Resources