File() function always return false

Responder
angeiras
Mensajes: 11
Registered for: 2 years 5 months
Brazil

File() function always return false

Mensaje por angeiras »

Hi all,

This sample prg works as expected, when compiled using hbmk2 on ubuntu 18.04 64 bits (shows the content of menu.json file)
Using mod_harbour.v2, file(...) test always return false.
why ? someone can confirm this ?

Código: Seleccionar todo

function main()
   local hMenu, cKey, cTemp

   if File("menu.json")
      cTemp := memoread("menu.json")
      hMenu := hb_jsondecode(cTemp)

      for EACH cKey in hMenu
         ? cKey["menuName"]
         ? cKey["menuIcon"]
         ? cKey["menuAction"]
         ? replicate("-",20)
      next
   else
      ? "menu.json not found"
   endif
return NIL
menu.json file:

Código: Seleccionar todo

[
  { "menuName"  : "Home",
    "menuIcon"  : "fas fa-home",
    "menuAction": "file1.prg",
    "menuActive": "true"
  },
  { "menuName"  : "Dashboard",
    "menuIcon"  : "fas fa-desktop",
    "menuAction": "file2.prg",
    "menuActive": "false"
  },
  { "menuName"  : "Billing",
    "menuIcon"  : "fas fa-database",
    "menuAction": "file3.prg",
    "menuActive": "false"
  },
  { "menuName"  : "Reports",
    "menuIcon"  : "fas fa-print",
    "menuAction": "file4.prg",
    "menuActive": "false"
  }
]
Best Regards,

Manoel

diegof
Mensajes: 42
Registered for: 3 years
Argentina

Mensaje por diegof »

Use
File( hb_getenv( 'PRGPATH' ) + '/menu.json' )
menu.json must be in the same path as your prg

hb_getenv( 'PRGPATH' ) ->
https://github.com/mod-harbour/mod_harb ... e.prg#L116

Diego.

angeiras escribió: Vie Mar 04, 2022 5:15 am Hi all,

This sample prg works as expected, when compiled using hbmk2 on ubuntu 18.04 64 bits (shows the content of menu.json file)
Using mod_harbour.v2, file(...) test always return false.
why ? someone can confirm this ?

Código: Seleccionar todo

function main()
   local hMenu, cKey, cTemp

   if File("menu.json")
      cTemp := memoread("menu.json")
      hMenu := hb_jsondecode(cTemp)

      for EACH cKey in hMenu
         ? cKey["menuName"]
         ? cKey["menuIcon"]
         ? cKey["menuAction"]
         ? replicate("-",20)
      next
   else
      ? "menu.json not found"
   endif
return NIL
menu.json file:

Código: Seleccionar todo

[
  { "menuName"  : "Home",
    "menuIcon"  : "fas fa-home",
    "menuAction": "file1.prg",
    "menuActive": "true"
  },
  { "menuName"  : "Dashboard",
    "menuIcon"  : "fas fa-desktop",
    "menuAction": "file2.prg",
    "menuActive": "false"
  },
  { "menuName"  : "Billing",
    "menuIcon"  : "fas fa-database",
    "menuAction": "file3.prg",
    "menuActive": "false"
  },
  { "menuName"  : "Reports",
    "menuIcon"  : "fas fa-print",
    "menuAction": "file4.prg",
    "menuActive": "false"
  }
]
Best Regards,

Manoel

angeiras
Mensajes: 11
Registered for: 2 years 5 months
Brazil

Mensaje por angeiras »

Hi Diego,

It works !!

Thanks again for your help,

Manoel

Responder