is it possible insert an array in a hash ?

100 views
Skip to first unread message

nikk...@gmail.com

unread,
Jun 12, 2025, 10:38:21 AMJun 12
to Harbour Users
Hi guys

never tested so i have this question : 

is it possible insert a bidimensional array in a hash ?

example : 
FUNCTION Main()
LOCAL hResponse  := {=>}
LOCAL aDATA1  := {}
LOCAL nTOTAL := 0
LOCAL nY := 0
LOCAL nK := 0

hResponse :=  insert_array_hash()
adata1  :=  hb_hGet( hResponse, "vector" )

* this is for simplyfing calcs
FOR nY := 1 TO 2
    FOR nK := 1 TO 2
         nTOTAL += aDATA1[ nY, nK ]
    NEXT
NEXT

?? nTOTAL

RETURN NIL
* eof

FUNCTION insert_array_hash()
LOCAL hSample := {=>}
LOCAL aDATA := {}

aDATA 1,1 ] := 1
aDATA[ 1,2 ] := 2
aDATA[ 2,1 ] := 3 
aDATA[ 2,2 ] := 4

hbset( hsample, "key1", 10 )
hbset( hsample, "key2", "pluto" )
hbset( hsample, "key3", .T. )
hbset( hsample, "key4", ctod( "01/01/2025" )  )

hbset( hsample, "vector", aDATA )

RETURN( hSample )
* eof


oleksa

unread,
Jun 12, 2025, 11:04:01 AMJun 12
to harbou...@googlegroups.com
Hi,

try that

func main()

  local hResponse := { => }
  local aData := { { 1, 2 }, { 3, 4 } }
  local nTotal := 0

  hResponse[ "vector" ] := aData

  aEval( hResponse[ "vector" ], {| xArr | aEval( xArr, {| x | nTotal += x } ) } )

  ?nTotal

  return

Regards,
Oleksii

12 червня 2025, 17:38:27, Від "nikk...@gmail.com" <nikk...@gmail.com>:

--
You received this message because you are subscribed to the Google Groups "Harbour Users" group.
Unsubscribe: harbour-user...@googlegroups.com
Web: https://groups.google.com/group/harbour-users
---
You received this message because you are subscribed to the Google Groups "Harbour Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to harbour-user...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/harbour-users/5461ca8a-ab69-40ba-9eae-89ca5accc4aan%40googlegroups.com.

HBQuerier

unread,
Jun 12, 2025, 11:29:20 AMJun 12
to Harbour Users
Function Test
LOCAL hSampleHash
LOCAL hSampleHash2
LOCAL aDATA1  := {}
LOCAL aDATA2  := {}
Local aA := {}
Local aB := {}
Local sA := {}
Local sB := {}

 aData1 := {  {1,2}, { 3,4 }  }
 aData2 := {  {5,6}, { 7,8 }  }


hSampleHash := { "A" =>  aData1, "B" => aData2  }
hSampleHash2 := { "A" =>  "First", "B" => "Second"  }


// Returns aData1
aA := hb_HGetDef( hSampleHash, "A" )
// Returns aData2
aB := hb_HGetDef( hSampleHash, "B" )

// Returns first
sA := hb_HGetDef( hSampleHash2, "A" )

// Returns Second
sB := hb_HGetDef( hSampleHash2, "B" )


RETURN Nil

nikk...@gmail.com

unread,
Jun 12, 2025, 12:03:25 PMJun 12
to Harbour Users
Thanks Oleskii, 

but that was an example to explain the issue :  

the real problem arise from a function that have to return only an hash.

one solution is returning an hash and an array, but  i prefer return only an hash

regards

Domenico

oleksa

unread,
Jun 12, 2025, 12:11:36 PMJun 12
to harbou...@googlegroups.com
func main()

  local hResponse := insert_array_hash()
  local nTotal := 0

  aEval( hResponse[ "vector" ], {| xArr | aEval( xArr, {| x | nTotal += x } ) } )

  ?nTotal

  return

func insert_array_hash()
  local aData := { { 1, 2 }, { 3, 4 } }
  local h_hash := { "vector" => aData }

return h_Hash

Regards,
Oleksii

12 червня 2025, 19:03:31, Від "nikk...@gmail.com" <nikk...@gmail.com>:

nikk...@gmail.com

unread,
Jun 12, 2025, 12:14:17 PMJun 12
to Harbour Users
thanks to all

regards
Reply all
Reply to author
Forward
0 new messages