String to Progress Bar max value.

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?)"
 
P

Peter Duniho

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
 
A

Andre Prins

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

progressBar1.Maximum is an int so you should use

progressBar1.Maximum = Convert.ToInt32(FoundVal)

hth
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top