String to Progress Bar max value.

  • Thread starter Thread starter RP
  • Start date Start date
R

RP

I have a routine that returns one column value in string. This time I
need to get total records in a table. So this routine is returning it
in string. I want to convert this value to an appropriate data type
that can be set as a maximum value for progress bar.

I tried:

progressBar1.Maximum = Convert.ToInt64(FoundVal)

but it is not working. It generates error:

"Error 10 Cannot implicitly convert type 'long' to 'int'. An explicit
conversion exists (are you missing a cast?)"
 
RP said:
progressBar1.Maximum = Convert.ToInt64(FoundVal)

but it is not working. It generates error:

"Error 10 Cannot implicitly convert type 'long' to 'int'. An explicit
conversion exists (are you missing a cast?)"

Look at the error. It is telling you that you have a "long" value,
which you are trying to put into an "int" value. It is also telling you
that the compiler will not implicitly convert from one to the other, but
that you can cast it explicitly if you want to.

Now, it's not at all clear to me that converting to an Int64 (same as
"long") makes sense anyway. Since the target is an Int32 (same as
"int"), you should just convert to an Int32 in the first place.

Then you'll have no compile error there.

Compiler errors are not always clear or directly helpful. But most of
the time they are. Take the time to look at what they say, and in many
cases you'll find the error is giving you very specific instructions on
what's wrong (in this case, mis-matched types).

Pete
 
RP said:
progressBar1.Maximum = Convert.ToInt64(FoundVal)

progressBar1.Maximum is an int so you should use

progressBar1.Maximum = Convert.ToInt32(FoundVal)

hth
 
Back
Top