get data from sd card

hi everyone i am relatively new to the Arduino programming, here I have cod that works without problems, he writes to the SD card and read data from it. But when I want to use this data from sd card does not work. For example, the number is always 0 and the text is empty. (Here is a picture of serial_monitor)

#include <SPI.h>
#include <Ethernet.h>
#include <SD.h>

 String Text; // Text = "my text!"
 int Num;    //  Num  = 123

  File myFile;
  
void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);

   if (!SD.begin(4)) {
   Serial.println(" sd error");
   return;
   }
   Serial.println(" sd ok");
 
   readSDSettings();
}

void loop() {
  // put your main code here, to run repeatedly:

    myFile = SD.open("myfiles.txt");
       if (myFile) {
    Serial.print ("Text is: ");
        Serial.println (Text);
    Serial.print ("Numbre is: ");
        Serial.println (Num);
      }

    // close the file:
    myFile.close();
delay(1000);
}
 
void readSDSettings() {

  char character;
  String settingName;
  String settingValue;
  myFile = SD.open("myfiles.txt");


  if (myFile) {
    while (myFile.available()) {
      character = myFile.read();
      while ((myFile.available()) && (character != '[')) {
        character = myFile.read();
      }
      character = myFile.read();
      while ((myFile.available()) && (character != '=')) {
        settingName = settingName + character;
        character = myFile.read();
      }
      character = myFile.read();
      while ((myFile.available()) && (character != ']')) {
        settingValue = settingValue + character;
        character = myFile.read();
      }
      if (character == ']') {

        //Debuuging Printing
        Serial.print("Name: ");
        Serial.println(settingName);
        Serial.print("Value: ");
        Serial.println(settingValue);

        // Apply the value to the parameter
        applySetting(settingName, settingValue);
        // Reset Strings
        settingName = "";
        settingValue = "";
      }
      
    }
           
    // close the file:
    myFile.close();
  } else {
    // if the file didn't open, print an error:
    Serial.println("error opening myfiles.txt");
  }

} // readSDSettings() END



// Writes A Configuration file
void writeSDSettings() {

  // Delete the old One
  SD.remove("myfiles.txt");
  // Create new one
  myFile = SD.open("myfiles.txt", FILE_WRITE);
  
  // writing in the file works just like regular print()/println() function
  myFile.print("[");
  myFile.print("Text=");
  myFile.print(Text);
  myFile.println("]");

  myFile.print("[");
  myFile.print("Numbre=");
  myFile.print(Num);
  myFile.println("]");

 
  // close the file:
  myFile.close();
  //Serial.println("Writing done.");

} // writeSDSettings()


void applySetting(String settingName, String settingValue) {
  // if(settingName == "exINT") {
  // exINT=settingValue.toInt();
  // }
  // if(settingName == "exFloat") {
  // exFloat=toFloat(settingValue);
  // }
  // if(settingName == "exBoolean") {
  // exBoolean=toBoolean(settingValue);
  // }
  // if(settingName == "exLong") {
  // exLong=toLong(settingValue);
  // }
}


// converting string to Float
float toFloat(String settingValue) {
  char floatbuf[settingValue.length() + 1];
  settingValue.toCharArray(floatbuf, sizeof(floatbuf));
  float f = atof(floatbuf);
  return f;
}

long toLong(String settingValue) {
  char longbuf[settingValue.length() + 1];
  settingValue.toCharArray(longbuf, sizeof(longbuf));
  long l = atol(longbuf);
  return l;
}

// Converting String to integer and then to boolean
// 1 = true
// 0 = false
boolean toBoolean(String settingValue) {
  if (settingValue.toInt() == 1) {
    return true;
  } else {
    return false;
  }
}

You are doing this in loop()

        Serial.print ("Numbre is: ");
        Serial.println (Num);

but where are you setting Num ?

it is for the test "Serial.print", but I need this number later for the statements and other things, that number is on the sd card written, look at the picture (it is 123), and I can not get it in loop. When I call a readSDSettings(); then it works.

look at the picture

I'm NOT looking at a picture of text. It's TEXT, damn it. Post it AS TEXT!

sloba88:
it is for the test “Serial.print”, but I need this number later for the statements and other things, that number is on the sd card written, look at the picture (it is 123), and I can not get it in loop. When I call a readSDSettings(); then it works.

Yes. of course you get something written to the console because you have this at the end of setup():

readSDSettings();

But in the loop() you print the values of some variables like “Text” and “Num” without getting them from the file. Why not get these values first from the SD card before attempting to print them out ?

"PaulS" here it is the text from the serial monitor

sd Ok
Name: Number
Value: 123
Name: Text
Value: my text!
Text is:
Number is: 0
Text is:
Number is: 0
Text is:
Number is: 0
Text is:
Number is: 0
Text is:
Number is: 0
.....

But in the loop() you print the values of some variables like "Text" and "Num" without getting them from the file.

yes, but how to get them from the file?

yes, but how to get them from the file?

You already KNOW how to get data from the file. Why YOU can't assign the data to the appropriate variable is something YOU need to explain.

I know how, when to call readSDSettings();, but it means nothing to me, l can not store a value in variable. I've already said that I'm new to this programming and all I need is to store a value from sd card to variable in Arduino, so I could later use it.

Thus it is written on the sd card

[Number=123]
[Text=my text!]

I tried with this code

myFile = SD.open("myfiles.txt");
  Serial.write(myFile.read()); 
  Num = (myFile.read());
  //Serial.println();
  Serial.println(Num);
  myFile.close();

but this comes out on serial monitor

Numbre is: 78
[78
Numbre is: 78
[78
......

You understand, I hope, that reading from the file advances the pointer in the file. Reading one character, and printing it to the serial port, and then reading the next character, and storing it in Num, does not make sense.

Reading from a file reads characters. It does NOT convert the characters to ints, and it does not read all the characters that make up an int.

I understand completely but I do not know a better way, if you have a better suggestion tell me ... This is a project that works through a web server and I need to somehow store values that have been sent from web server, and in case somehow arduino being reset, again load last value to variables (There are about 10 variables). I found this example and used him.