How to use GetValue ?

ad.txt

Member
Joined
Oct 4, 2022
Messages
17
Programming Experience
Beginner
Hi !

I'm new to C# so I don't know everything about it.
My goal here is to pick up some values from a scanner and to put them into a form.
I've written this code but I have some error on the GetValue.
Maybe I don't use it correctly ?
(The numbers 101, 102, 103 and 104 in the GetValue refer to the physical ports of the scanner.)

C#:
public Form1()
{
    InitializeComponent();
}

public double Daq1 = 0.0;
public double Daq2 = 0.0;
public double Daq3 = 0.0;
public double Daq4 = 0.0;

public double GetValue(int);

private void Form1_Load(object sender, EventArgs e)
{
    Daq1 = GetValue(101);
    Daq2 = GetValue(102);
    Daq3 = GetValue(103);
    Daq4 = GetValue(104);
    
    label24.Text = Daq1.ToString();
    label25.Text = Daq2.ToString();
    label26.Text = Daq3.ToString();
    label27.Text = Daq4.ToString();
}
 
Firstly, what errors? Secondly, what are you expecting that GetValue to do? It looks like it's supposed to be a method but it has no body, so it can't do anything. Is it maybe supposed to be mapped to a function in an unmanaged library? Please provide ALL the relevant information.
 
Thank you for your response, sorry for the lack of info

The error that I have is like you said : Form()1.GetValue(int)' must declare a body because it is not marked abstract, extern or partial."
The thing is that I don't know what it really means ...

I want the GetValue to pick up the data from the pins 101, 102, 103 and 104 of the scanner.
I don't know if it can work like that or if I'm expecting magic but it's what I would like to do.
 
You need to write code as the body of that method that will read the pin of your scanner. The compiler cannot read your mind and figure out that you want to read from the scanner and supply the code for you.
 
Do you mean that I have to write it like that ? :

C#:
:
public Form1()
{
    InitializeComponent();
}

public double Daq1 = 0.0;
public double Daq2 = 0.0;
public double Daq3 = 0.0;
public double Daq4 = 0.0;

public double GetValue(int);
{
    Daq1 = GetValue(101);
    Daq2 = GetValue(102);
    Daq3 = GetValue(103);
    Daq4 = GetValue(104);
}
private void Form1_Load(object sender, EventArgs e)
{
    
    label24.Text = Daq1.ToString();
    label25.Text = Daq2.ToString();
    label26.Text = Daq3.ToString();
    label27.Text = Daq4.ToString();
}
 
No, GetValue can't call itself and have the data magically appear. You have to actually write some code that will communicate with the scanner to get the desired data. I would guess that there is some documentation and/or an SDK for that scanner that will provide some guidance as to what is required. We can't tell you what's required because it would be different for every hardware device.
 
Unfortunately, that won't really do anything for you since your are calling GetValue() recursively. The first time you call GetValue() from someplace else, you will get a stack overflow because line 14 will cause execution to go back to line 12.
 
Back
Top Bottom