|
What happens when the user keeps entering invalid inputs and the stack runs out of space?
|
|
|
|
|
We all get sucked into a hell dimension?
This space for rent
|
|
|
|
|
Hell is other people's code
|
|
|
|
|
lol this is a command line application.... the console will keep on scrolling down and never run out of space... the space is infinite.
|
|
|
|
|
Much to learn you still have, young padawan.
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
I wasn't talking about the console but the stack. The correct answer to my question was that you'll get a stack overflow exception and your app will terminate.
|
|
|
|
|
I hadn't realised that Console applications rewrote the laws of the stack. Dagnabit, from now on, all my applications are going to be console applications if that's all it takes to avoid stack issues.
This space for rent
|
|
|
|
|
Please do use braces (brackets). As a beginner you shouldn't yet "experiment" with omitting them.
Please do not use labels ("HOME:"). Labels only make sense with the keyword goto and you should never, ever use goto until you exactly understand why I write this and are able to identify the 0,00001% case where goto might be excusable.
I assume you haven't yet learned about creating and calling own methods (which would be the best solution to letting the user retry entering a value).
So here's a comparatively good-style snippet for allowing the user to re-enter a value greater than zero if he entered a wrong value the first time or repeatedly:
Console.WriteLine("Enter any number greater than 0: ");
string input = Console.ReadLine();
int value1;
while (!Int32.TryParse(input, out value1) || value1 <= 0)
{
Console.WriteLine("Invalid input. Enter any number greater than 0: ");
input = Console.ReadLine();
}
Sidenote: In C#, local identifiers should be declared where you first need them, not all at the top of a method.
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
Sascha Lefèvre wrote: you should never, ever use goto until you exactly understand why I write
Gets my vote!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Sascha Lefèvre wrote: Sidenote: In C#, local identifiers should be declared where you first need them, not all at the top of a method. I wonder where this habit comes from. I always declare vars at the top of the method.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I think it makes sense from a semantic point of view: You see a declaration and you know it's the first occurence of that identifier. It also saves some lines of code. Why do you prefer the top-declaration?
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
I think it may have come from the days when it was possible to declare a variable multiple times, VB5 allowed that and possibly 6, my milk languages. I think I have broken most of the old habits, annoying to realise some are still in use.
I do recall declaring and enum called Date with a value of 2, screwed up so many things. It was a long time ago!
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Int a = -1;
Int hhhhhh = 0;
While (a <= 0)
{
Console.write("tell me " + hhhhhh.ToString() + "nd number ");
a = int.Parse(Console.ReadLine());
hhhhhh++;
}
Console.WriteLine("homework complete");
modified 3-Apr-16 13:42pm.
|
|
|
|
|
I haven't used any
Console.WriteLine to display "Input string was not in a correct format" . I am trying to get data from database and save it in a double 2D array. One row in each array entry. This is my code :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SqlClient;
namespace Outliers2010_Console
{
class Program
{
static void Main(string[] args)
{
try
{
double[][] rawData = new double[20][];
string con = @"Data Source=Kitty-PC\SQLEXPRESS;Initial Catalog=kitty12;Integrated Security=True";
SqlConnection sql = new SqlConnection(con);
string cms = "SELECT TOP 20 * FROM churn_or";
SqlCommand cmd = new SqlCommand(cms,sql);
sql.Open();
SqlDataReader dt = cmd.ExecuteReader();
int i = 0;
if (dt.HasRows)
{
Console.WriteLine("datareader has rows");
while (dt.Read())
{
Console.WriteLine("read from dt");
rawData[i] = new double[] {Convert.ToDouble (dt[0]), Convert.ToDouble(dt[1]), Convert.ToDouble(dt[2]), Convert.ToDouble(dt[3]), Convert.ToDouble(dt[4]), Convert.ToDouble(dt[5]), Convert.ToDouble(dt[6]), Convert.ToDouble(dt[7]), Convert.ToDouble(dt[8]), Convert.ToDouble(dt[9]), Convert.ToDouble(dt[10]), Convert.ToDouble(dt[11]), Convert.ToDouble(dt[12]), Convert.ToDouble(dt[13]), Convert.ToDouble(dt[14]), Convert.ToDouble(dt[15]), Convert.ToDouble(dt[16]), Convert.ToDouble(dt[17]), Convert.ToDouble(dt[18]), Convert.ToDouble(dt[19]), Convert.ToDouble(dt[20]), Convert.ToDouble(dt[21]), Convert.ToDouble(dt[22]), Convert.ToDouble(dt[23]), Convert.ToDouble(dt[24]), Convert.ToDouble(dt[25]), Convert.ToDouble(dt[26]), Convert.ToDouble(dt[27]), Convert.ToDouble(dt[28]), Convert.ToDouble(dt[29]), Convert.ToDouble(dt[30]), Convert.ToDouble(dt[31]), Convert.ToDouble(dt[32])};
Console.WriteLine(rawData[i]);
i++;
}
}
sql.Close();
}
catch()
{}
}
}
}
I am not getting any error nor exception nor even a message, but in output instead of getting value of rawData which I need to be printed. I am getting "Input string was not in a correct format" . I have extensively googled and even tried the suggestions but all are talking about exceptions and errors which are not solving my issue. haven't found any content like that
modified 2-Apr-16 8:20am.
|
|
|
|
|
Use the debugger.
Put a breakpoint on the line
Console.WriteLine("read from dt");
and run your app.
When it hits the line, it will stop and let you look at exactly what is happening.
Look at each of the values in your DataReader - at least one of them is not a string representation of a double value.
We can't do that for you: we don't have your data!
BTW: Two things.
1) You should use a using block for SqlConnections, SqlCommands, and so forth to ensure they are correctly disposed.
2) Unless you specify a sort order in your SQL query via a ORDER BY clause, SQL is at liberty to return rows in any order it feels like - so you may not get the same values in two consecutive runs. Always specify the order if you want to return specific rows!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
I am working on a C# project which is related to Write/Read RFID NXP tag. Reader model is Feig obid i-scan MR102. This is USB device. They provided SDK. I can read default serial number of NXP tag with this SDK. My problem is, I need to Write ISBN of a book in NXP tag and Turn security ON when the book indoor into library. When the book will be issued, I need to Read the ISBN of this book and Turn security OFF. I am attaching the SDK, if you know how to do this, please give me solution. Thanks.
SDK : <a href="https://drive.google.com/file/d/0B5vXfWlYNNbVVkxDWnEyLTBuZEU/view?usp=sharing">ID_ISC.SDK.NET_V04.06.10.zip - Google Drive</a>
|
|
|
|
|
You should talk to the people who created it - the device and the API - they should provide technical support and will know more about their product than we will. If they don't, then find another supplier and demand your money back!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
I asked them, they told me i will find read/write functions in sdk, but i did not get it from there. Thanks for your reply.
|
|
|
|
|
Well, go back to them and ask "Where?" and "How do I use it?"
They know their product - it's unlikely that anyone here is going to, or at least anyone that is going to see this and reply in a "reasonable time".
Seriously - if their technical support is just "it's in the API" with no further support documents or assistance, I'd be looking to my money back and a new supplier, as they clearly don't care...
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
You expect people to root around in an SDK without even a hint of who the vendor is?
Did you even bother to unzip it?
|
|
|
|
|
I really don't understand, why you are telling this. Vendor is, Feig. It's a german company.
|
|
|
|
|
Sorry .. my mistake ... I'll look some more.
|
|
|
|
|
Does not matter. If you have any idea, please help me. Thanks.
|
|
|
|
|
|
Gerry Schmitz wrote: You can write an "ID" to the device; that would be your ISBN, I presume.
Can you give me an example, how to read/write string in nxp tag?
Securiy READ/WRITE problem is solved, and I very greatfull to you for this.
Thanks in advance.
|
|
|
|