Visual Basic cannot display textbox information? - visual-studio

I am working on a vb program, and I am having an error (duh). I'm trying to display the contents of a users input (textbox) in a messagebox, but it's throwing a `System.InvalidCastException'. Here is my code:
Private Sub ThirteenButton1_Click(sender As Object, e As EventArgs) Handles ThirteenButton1.Click
' withdrawBtn
If IsNumeric(withdrawTxtBox.Text) Then
If Val(withdrawTxtBox.Text) > Val(My.Settings.accountBalanceBA) Then
MessageBox.Show("Error: You can not withdraw " + withdrawTxtBox.Text + ", you only have " + My.Settings.accountBalanceBA.ToString + ".")
ElseIf Val(withdrawTxtBox.Text) < Val(My.Settings.accountBalanceBA) Then
MessageBox.Show("Successfully withdrawn $" + Val(withdrawTxtBox.Text) + ". Your remaining balance is $" + Val(withdrawTxtBox.Text) - My.Settings.accountBalanceBA.ToString)
End If
End If
End Sub
Entering a number > the account balanceBA will work with no error, but once I enter a number < the balance, it throws the error.
Any help would be greatly appreciated.

The line
MessageBox.Show("Successfully withdrawn $" + Val(withdrawTxtBox.Text) + ". Your remaining balance is $" + Val(withdrawTxtBox.Text) - My.Settings.accountBalanceBA.ToString)
Specifically
Val(withdrawTxtBox.Text) - My.Settings.accountBalanceBA.ToString
is trying to subtract a string from a number. Use parenthesis to get the order of operations right.
(Val(withdrawTxtBox.Text) - My.Settings.accountBalanceBA).ToString

A little advise.. Just avoid using plus sign (+) when performing concatenation, specially when you have mathematical condition to concat with string. You can use "&" instead for concatenation.
Replace plus sign with "&" for best practices.
To correct your code.. you can remove the .ToString or place the .ToString out the subtraction.. after closing parenthesis. ).ToString You have to be careful in using parenthesis to avoid unexpected result or worst will encounter an error.
MessageBox.Show("Successfully withdrawn $" & Val(withdrawTxtBox.Text) & ". Your remaining balance is $" & Val(withdrawTxtBox.Text) - My.Settings.accountBalanceBA)
MessageBox.Show("Successfully withdrawn $" & Val(withdrawTxtBox.Text) & ". Your remaining balance is $" & (Val(withdrawTxtBox.Text) - My.Settings.accountBalanceBA).ToString

Related

MS Visual Studio (Reporting Services)

I've worked in SSRS for years but have never learned what this type of coding is actually named (which makes searching for solutions difficult), can anyone help please? Below is an example which allows the developer to have the code run as one continuous string. It also, if you're not familiar, allows for many powerful functions to be used that would otherwise (to my knowledge) not be available (e.g., IIF's, INSTR(JOIN()), SWITCH's, etc.).
=
" select distinct bn " &
" into #ST " &
" from frm_cr_2021 a " &
" join Md..nui_crssw b " &
" ON a.rc=b.cy"&MID(YEAR(Parameters!frm_dt.Value),3,2)&"_rc" &
" join nd_bs..dg_cv c " &
" on b.nd=c.nd " &
" where a.f_Dt<=#frm_dt and a.tr_dt>=#frmy_dt " &
"(select distinct c.ln,a.RC,A.Tr_Lv,a.P_Typ,a.P_Gp,a.Eff_Date,a.Term_Date from frm_"&YEAR(Parameters!frm_dt.Value)&" a "

Getting Microsoft VBScript runtime error '800a0009' on Checkout Cart

I'm really not very familiar with ASP, but the site I'm managing is spitting that error out to me. Here is the full code from the site:
Microsoft VBScript runtime error '800a0009'
Subscript out of range: '[number: 1]'
/shopping_sub.asp, line 715.
Here is the code from 697-728:
'Response.write strPass & "<p>"
'Response.write "Response: " & strResp
'Response.end
If strResp="ERROR" then
RESULT_num_shipping_options = -1
Session("ShipErrMsg")="To continue your order, please contact customer service regarding your contact information. Thank you."
Else
RESULT_num_shipping_options=1
vResp=Split(strResp,":")
Dim RESULT_shipping_description_array(4)
Dim RESULT_shipping_amount_array(4)
For I = 0 to UBound(vResp)
vResp2=Split(vResp(I),"|")
RESULT_shipping_description_array(I)=vResp2(0)
RESULT_shipping_amount_array(I)=vResp2(1)
Next
End If
Else
RESULT_num_shipping_options = -1
cShipping=0
End If
End If
'Response.write "Weight: " & siWeight & "<br/>"
'Response.write "Zip: " & receiverpostalcode & "<br/>"
'Response.write "Country: " & receivercountrycode & "<br/>"
It appears to start functioning after 7 items have been added to the cart, but anything less than that returns errors.
This doesn't happen with all products, so any idea?
Have you used a debugger to determine the value of vResp and the array length of vResp2?
My guess is that the response is not what you expected. If you can't force the api to always have the correct response, then you'll want to protect against it by checking the length of the split response before trying to access the value.
Another problem I see that is unrelated, is that if the UBound(vResp)_ > 4, then you'll get a similar error

SELECT * INTO Incomplete Query Clause

I seem to be doing something wrong in my OleDbCommand, but I don't know what it is. I am trying to create another table in my access database that is exactly the same as the first but with a different name, by copying everything from one and using SELECT INTO. I don't know why it doesn't work.
OleDbCommand copyAttendanceCommand = new OleDbCommand("SELECT * INTO '" + "Attendance " + DateTime.Now.Day + "/" + DateTime.Now.Month + "/" + DateTime.Now.Year + "' FROM Attendance",loginForm.connection);
copyAttendanceCommand.ExecuteNonQuery();
The Error message that I get says "Syntax error in query. Incomplete query clause." Does anyone know what that means?
Table or field names with spaces are not specified with '' around them, but with square brackets.
Your command should be:
"SELECT * INTO [Attendance " + DateTime.Now.Day + "/" + DateTime.Now.Month + "/"
+ DateTime.Now.Year + "] FROM Attendance"
You may even format your date to make the code more readable:
string today = DateTime.Today.ToString("d'/'M'/'yyyy");
string sql ="SELECT * INTO [Attendance " + today + "] FROM Attendance";
OleDbCommand copyAttendanceCommand = new OleDbCommand(sql, loginForm.connection);
copyAttendanceCommand.ExecuteNonQuery();

Alternatives to macros for accessing data objects

I'm about to begin implementing a new version of an Email marketing program for my company. The old version of the program program heavily depended on micros and has about 2000 lines to prepare data for an email campaign to be run. But I have read somewhere that macros are not the best solution to run such heavy tasks and it's better we keep them for simple things.
I'm quite new to QV and I'm the kind of person that likes to learn as I go and not complete a big reference book before I start a project. I'm good at C# and Java but I realized QlikView scripts are in either VBScript or JScript. I have no experience with them whatsoever but they don't look very complicated to me at first glance.
What I was wondering was whether there is a better way of handling data in QlikView? That means can I use another programming language or do you suggest I stick to the script languages provided by QV? Because one big problem I've seen is that as macros get larger they become very hard to debug.
In the old version of our program developed by one of my colleagues who has now left the company, as soon as there was an error in preparing the data, all we got was the macros window with no clue about where the error had taken place. As I would like to implement this project incrementally and little by little, I would like to have a good mechanism for trouble shooting rather than goring though a 2000-line script to understand where the problem comes from.
Your suggestions about how to bring this project to a safe shore are very welcome. So, any good plugins or 3rd party app to monitor the data and facilitate my implementation can help.
We are an outlier there. We are using the OCX and connect to it in winforms.
We have then standard c# code with everything debuggable and it makes everyone here very happy indead after using endless amount of time debugging javascripts.
The users use QV for selecting stuff and then we use the selected event in the OCX and pull the selected data from QV for postprocessing and tag the QV data with dynamic sql update.
I do not nessesarily recommend this method, but it has increased dramatically the development output for us when using QV for datamining and then processing the data selected.
Next project we are not going to use the OCX. But all the buisness logic and postprocessing is in a com visible c# dll' that we access through vbscript macro.
EDIT. More details
This is the current setup communicating with the document through OCX
Change a selection
axQlikMainApp.ActiveDocument.Fields("%UnitID").Clear();
var selSuccess = axQlikMainApp.ActiveDocument.Fields(cls.QlikView.QvEvalStr.Fields.UnitId).Select("(%UnitID)");
reset a sheet object
axQlikMainApp.ActiveDocument.ClearCache();
axQlikMainApp.ActiveDocument.GetSheetObject("Document\\MySheetObjectName").Restore();
get a string from QV
string res axQlikMainApp.ActiveDocument.Evaluate("=concat(Distinct myField1 &'|' & MyField2,'*')");
and can get horribly complicated
string res axQlikMainApp.ActiveDocument.Evaluate( "=MaxString({1 <%UnitID= {" + sUnitIds + #"}>}'<b>' & UnitName & '</b> \r\n bla bla bla:' & UnitNotesPlanning) & " +
"'\n title1: ' & Count({1 <%UnitID= {" + sUnitIds +#"},%ISODate={'" + qlickViewIsoDate + "'},Need = {'Ja'}" + MinusCalc + ">}Distinct %CivicRegNo) & " +
"'\n Title2: ' & Count({1 <%UnitID= {" + sUnitIds + #"},%ISODate={'" + qlickViewIsoDate + "'} " + recallMinusCalc + ">}DISTINCT RevGUID) & " +
"'\n Title3: ' & Count({1 <%UnitID= {" + sUnitIds + #"},%ISODate={'" + qlickViewIsoDate + "'},Need2 = {'Ja'}>}Distinct %CivicRegNo) & '" +
"\n Title4:' & MinString({1 <%UnitID= {" + sUnitIds + #"},FutureBooking = {1}>} Date(BookingStart) & ' Beh: ' & If(IsNull(ResourceDisplayedName),'_',ResourceDisplayedName)) &'" +
"\n Title5:' & MaxString({1 <%UnitID= {" + sUnitIds + #"},FutureBooking = {0}>} Date(BookingStart) & ' Beh: ' & If(IsNull(ResourceDisplayedName),'_',ResourceDisplayedName)) &''" +
" & MaxString({1 <%UnitID= {" + sUnitIds + #"}>}if(UnitGeo_isRelocatedOnSameGeo=1,'\nOBS! Multiple geo addresses. Zoom!',''))" +
""
);

Issue using Oracle date function with Spring's NamedParamenterJdbcTemplate

I'm having an issue trying to get my SQL query which works fine in SQL Developer (Oracles free database tool) to also work using Spring's NamedParameterJdbcTemplate class.
My query is:
String sql = " SELECT COUNT(*) FROM ( " +
" SELECT FE.USR_ID, MAX(FE.DATE_FIRST_SUB) AS SUB_DATE " +
" FROM FC, FE " +
" WHERE FC_STATUS = 'MEMBER' " +
" AND FC.FC_SPC_ID = :spcId " +
" AND FE.FE_USR_ID = FC.FC_USR_ID " +
" AND FE.DATE_FIRST_SUB IS NOT NULL " +
" GROUP BY FE_USR_ID " +
" ) " +
" WHERE SUB_DATE BETWEEN TO_DATE('01-JUN-2011', 'DD-MON-YYYY') AND TO_DATE('01-JUL-2011', 'DD-MON-YYYY') ";
It has something to do with my dates, formatting perhaps? When I don't use the WHERE clause in the outer select it works, when it's included 0 is returned from the count - as I mentioned running the SQL directly returns expected results.
Any advice?
Thanks.
Oh my, I was in fact looking at the wrong database!!

Resources